я думаю, что это сработает
for c in [c for c in df.columns if np.issubdtype(df[c].dtype , np.number)]:
df[c] = np.log(df[c])
Пример кода: import pandas as pd import numpy as np
df = pd.DataFrame(
[
[2, 4, "A"],
[4, 5, "C"],
[5, 4, "B"],
[10, 4.2, "A"],
[9, 3, "B"],
[3, 3, "C"]
], columns=['data1', 'data2', 'Categories'])
for c in [c for c in df.columns if np.issubdtype(df[c].dtype , np.number)]:
df[c] = np.log(df[c])
Вывод:
data1 data2 Categories
0 0.693147 1.386294 A
1 1.386294 1.609438 C
2 1.609438 1.386294 B
3 2.302585 1.435085 A
4 2.197225 1.098612 B
5 1.098612 1.098612 C