我知道如何将函数应用于Pandas-DataFrame中存在的所有列。但是,我还没有弄清楚如何在使用Polars-DataFrame时实现这一点。
我查看了《Polars 用户指南》中专门讨论此主题的部分,但我还没有找到答案。在这里,我附上了我不成功的尝试的代码片段。
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 …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Python 中的 Seaborn 包来可视化一些数据。特别是,我想使用该catplot(kind='bar')函数(以前命名为factorplot())。我的数据框看起来像这样(列'x','col','row'并且'hue'是绝对的):
x y dy col row hue
0 4 9 0.766591 1 0 2
1 5 9 0.688683 0 1 0
2 0 7 0.707982 0 0 1
3 3 6 0.767210 2 1 0
4 3 8 0.287153 0 1 0
Run Code Online (Sandbox Code Playgroud)
我想使用不确定性列'dy'来表示'y'. Seaborn catplots 执行的默认引导或标准偏差误差条不能为我提供令人满意的解决方案。
在这里,我提供了最小完全可验证的示例:
import pandas as pd
import numpy.random as npr
import seaborn as sns
npr.seed(seed=0) …Run Code Online (Sandbox Code Playgroud)