Okay, this works and I tested it:
import pandas as pd
#----------------------------------------
# Prepare the data in df.
#----------------------------------------
from io import StringIO
TESTDATA = StringIO("""Index;column_of_interest
1;21678849
2;37464859
3;barbara
4;28394821
5;francis""")
df = pd.read_csv(TESTDATA, sep=";")
#----------------------------------------
# The actual code to solve the problem.
#----------------------------------------
def is_integer(x):
try:
int(x)
return True
except ValueError:
return False
print([is_integer(x) for x in df['column_of_interest']])
Output is
[True, True, False, True, False]
Of course some of the code doesn't apply to you, but I wanted a full working example which I (and others) could actually test. I assume you can pick out what you need from it.
The code to test for integerness was taken from https://stackoverflow.com/a/1267145/1629102.
And finally code that adds the data as a new column:
import pandas as pd
#----------------------------------------
# Prepare the data in df.
#----------------------------------------
from io import StringIO
TESTDATA = StringIO("""Index;column_of_interest
1;21678849
2;37464859
3;barbara
4;28394821
5;francis""")
df = pd.read_csv(TESTDATA, sep=";")
#----------------------------------------
# The actual code to solve the problem.
#----------------------------------------
def is_integer(x):
try:
int(x)
return True
except ValueError:
return False
is_integer_list = [is_integer(x) for x in df['column_of_interest']]
df["Is_integer"] = is_integer_list
print(df)
with this output:
Index column_of_interest Is_integer
0 1 21678849 True
1 2 37464859 True
2 3 barbara False
3 4 28394821 True
4 5 francis False