I searched for a solution on the site, but I couldn't find anything relevant, only outdated code. I am new to the Pandas library and I have the following dataframe
as an example:
A | B | C | D | E |
---|---|---|---|---|
142 | 0.4 | red | 108 | front |
164 | 1.3 | green | 98 | rear |
71 | -1.0 | blue | 234 | front |
109 | 0.2 | black | 120 | front |
I would like to extract the name of the columns that contain numbers (integers and floats). It is completely fine to use the first row to achieve this.
So the result should look like this: ['A', 'B', 'D']
I tried the following command to get some of the columns that contained numbers:
dataframe.loc[0, dataframe.dtypes == 'int64']
Out:
A 142
D 108
There are two problems with this. First of all, I just need the name of the columns, but not the values. Second, this captures only the integer columns. My next attempt just gave an error:
dataframe.loc[0, dataframe.dtypes == 'int64' or dataframe.dtypes == 'float64']