gpt4 book ai didi

python - 如何在 Seaborn lmplot 中使用 pandas DataFrame 作为数据参数

转载 作者:行者123 更新时间:2023-12-01 03:40:03 26 4
gpt4 key购买 nike

查看lmplot documentation ,它显示

Parameters:

      x, y : strings, optional

Input variables; these should be column names in data.

data : DataFrame

Tidy (“long-form”) dataframe where each column
is a variable and each row is an observation.

我有一个 pandas 数据框 customers,我想将其用作 lmplot 的参数。如何将 pandas 数据框转换为整洁的(“长格式”)数据框以在 lmplot 中使用?

目前,我正在尝试执行以下操作:

sns.lmplot(customers["Length of Membership"], customers["Yearly Amount Spent"], customers)

(Seaborn 导入为 sns)。上面的 python 代码返回一个错误,其中包含很长的浮点列表。

最佳答案

感谢Bob Haffner仔细查看文档,DataFrame 根本不是问题,而是我传递的 X 和 Y 参数。

当我应该传递字符串时,我正在传递系列,如下所示:

sns.lmplot("Length of Membership", "Yearly Amount Spent", customers)

关于python - 如何在 Seaborn lmplot 中使用 pandas DataFrame 作为数据参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39737226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com