You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In step 10, we want to multiply all numerical values by 10.
The provided solution is: df.applymap(times10).head(10)
But this is very slow, because it runs a regular python function on every element in the dataframe.
Better is to test each column's type, and then use pandas built in multiplication on the whole column:
for colname, coltype in df.dtypes.to_dict().items():
if coltype.name in ['int64']:
df[colname] = df[colname] * 10
I used %%timeit to test the two solutions. On this small dataset, my solution is 5x as fast (1.1ms vs 5.8ms). The difference would get larger with a larger dataset.
The text was updated successfully, but these errors were encountered:
In step 10, we want to multiply all numerical values by 10.
The provided solution is:
df.applymap(times10).head(10)
But this is very slow, because it runs a regular python function on every element in the dataframe.
Better is to test each column's type, and then use pandas built in multiplication on the whole column:
I used
%%timeit
to test the two solutions. On this small dataset, my solution is 5x as fast (1.1ms vs 5.8ms). The difference would get larger with a larger dataset.The text was updated successfully, but these errors were encountered: