'What would be the pandas equivalent for the for-loop below?
I have a function called unit_unify() that I want to apply to every column of the dataframe. I have been trying to devise the pandas equivalent using apply/apply map, but have not been successul.
Here is the for loop
for i in df.columns:
df[i] = unit_unify(df[i], unit_dict)
Here is the attempt at the pandas equivalent of the for loop
df = df.apply(lambda col: unit_unify(df[col], unit_dict))
Solution 1:[1]
You may check the performance for the for loop and apply:link
[df[i] = unit_unify(df[i], unit_dict) for i in df.columns]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BENY |
