I have a dataframe with multiple columns.
df = pd.DataFrame({'A' : [1.0, 3.0, 4.0, 5.0, 2.0],
'B' : [2, 4, 5, 8, 9],
'C' : [1.8, 4.1, 4.0, 5.6, 2.0],
'D' : [99, 100, 101, 101, 99],
'D' : [99.0, 1000.0, np.nan, 101.0, 99.0]})
df
A B C D
0 1.0 2 1.8 99.0
1 3.0 4 4.1 1000.0
2 4.0 5 4.0 NaN
3 5.0 8 5.6 101.0
4 2.0 9 2.0 99.0
After applying dtype, we see that columns A and D are considered as float.
df.dtypes
A float64
B int64
C float64
D float64
dtype: object
I want to find all columns in my df, which can be represented as integers but are considered as floats.
Expected result:
['A', 'D']
The list contains all columns, which are considered as floats but actually can be represented as integers.
How can I find these columns?