I know how to apply a function to all columns present in a Pandas-DataFrame. However, I have not figured out yet how to achieve this when using a Polars-DataFrame.
I checked the section from the Polars User Guide devoted to this topic, but I have not find the answer. Here I attach a code snippet with my unsuccessful attempts.
import numpy as np
import polars as pl
import seaborn as sns
# Loading toy dataset as Pandas DataFrame using Seaborn
df_pd = sns.load_dataset('iris')
# Converting Pandas DataFrame to Polars DataFrame
df_pl = pl.DataFrame(df_pd)
# Dropping the non-numeric column...
df_pd = df_pd.drop(columns='species') # ... using Pandas
df_pl = df_pl.drop('species') # ... using Polars
# Applying function to the whole DataFrame...
df_pd_new = df_pd.apply(np.log2) # ... using Pandas
# df_pl_new = df_pl.apply(np.log2) # ... using Polars?
# Applying lambda function to the whole DataFrame...
df_pd_new = df_pd.apply(lambda c: np.log2(c)) # ... using Pandas
# df_pl_new = df_pl.apply(lambda c: np.log2(c)) # ... using Polars?
Thanks in advance for your help and your time.
python-polars
? – Deniablepython-polars
tag to the original question tags. – Decode