首页 > 解决方案 > 遍历数据框名称

问题描述

我想在 for 循环中打印 Dataframe 的名称,但是我不正确当我遍历数据集列表时,我得到了数据集。例如,如果我尝试使用 str(d),我会将所有数据集作为字符串。d.name() 也不起作用。

我该怎么做才能将 Dataframe 的名称打印为字符串?

提前致谢!

PD:我收到此错误,“AttributeError:'DataFrame' 对象没有属性'名称'”

# Define lists
datasets = [train_data, test_data]
features = ['Age', 'Fare']
# Create function
fig, outliers = plt.subplots(figsize=(20,10), ncols=4)
row, col = 0, 0
for f in features:
    for d in datasets:
        sns.boxplot(x=d[f], orient='v', color=pal_titanic[3], ax=outliers[col])
        outliers[col].set_title(f + 'in' + d)
        col = col + 1    

标签: pythonpandasdataframe

解决方案


推荐阅读