I have a data frame (in pandas format) that is composed of numerical and non-numerical columns. I want to divide only numerical cells by a scalar, but I can't find any function for automatically doing that without explicitly defining the numerical columns (since the data frame is large and I can't exactly define the numerical columns). I found pd.divide, but it didn't work (I encounter the following error: unsupported operand type(s) for /: 'str' and 'int')
You can check the data type for a given column, though a more flexible option is to use try
to check if it works and skip otherwise. So you can just do:
for col in df:
try: df[col] /= scalar
except TypeError: pass