【问题标题】:Pandas Error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()Pandas 错误:ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()
【发布时间】:2021-08-14 11:42:49
【问题描述】:
plt.figure(figsize=(8,6))
sns.boxplot(df[features])
plt.show()

我想要 boxplot 但我遇到了这个错误 - ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。

【问题讨论】:

  • 什么是特征?

标签: python pandas matplotlib seaborn


【解决方案1】:

您需要先将数据框转长:

import pandas as pd
import seaborn as sns
df = sns.load_dataset("iris")
features = ['sepal_length','petal_width']

sns.boxplot(x = "variable",y="value",data = df[features].melt())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-01
    • 2021-09-15
    • 2019-01-24
    • 2020-05-27
    • 1970-01-01
    • 2021-03-21
    • 2021-05-27
    • 2021-04-07
    相关资源
    最近更新 更多