I have a dataframe which has 89 columns. Almost 40 of them are string and I just need the rest which are float and integer. How can delete all these 40 columns apart from deleting one by one? Ps. I have some nan values in my integer and float columns. Thanks in advance
Asked
Active
Viewed 35 times
0
-
2`df = df.select_dtypes(np.number)` – Chris Adams Mar 09 '20 at 10:21
-
What about `df.drop(columns=['col_to_del', ...])` or `df[['col_to_keep', ...]]`? – Serge Ballesta Mar 09 '20 at 10:24
-
This one is going to take a lot of time that's why I asked for a 'quick' way. For the first comment I've got an error - -> 'method' object is not subscriptable – samyil Mar 09 '20 at 10:30
-
Can you paste the exact line of code you run that produced that error please? – Chris Adams Mar 09 '20 at 10:39
-
info = house_info.select_dtypes[np.number] it was this one but I've found how to do with the answer of question that you shared – samyil Mar 09 '20 at 10:43
-
I just figured I've used wrong brackets sorry :) – samyil Mar 09 '20 at 10:44
-
yip, just needs rounded brackets `()` :) – Chris Adams Mar 09 '20 at 10:53