Is there any elegant way in a Pandas Dataframe with several columns of float64 and other types to make a global operation only on the float64 elements?
What I am looking for is to divide all float64 elements by 100, without having to target or name specific columns.
You could use df.select_dtypes().
cols = df.select_dtypes(include=['float64']).columns
df[cols] = df[cols] / 100.
This will divide all float64 columns by 100. Note that if you have mixed object columns with some float64 cells, they won't be divided (your question wasn't totally clear about whether you wanted to act on columns or elements)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With