【问题标题】:How to use a pandas DataFrame as data parameter in Seaborn lmplot如何在 Seaborn lmplot 中使用 pandas DataFrame 作为数据参数
【发布时间】:2017-02-05 19:51:00
【问题描述】:

查看lmplot documentation,它显示

参数:

      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.

我有一个熊猫数据框customers,我想将它用作lmplot 的参数。如何将我的 pandas 数据框转换为整洁(“长格式”)数据框以用于lmplot

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

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

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

【问题讨论】:

  • 看起来前两个参数(x 和 y)应该是字符串,但是你传递了两个系列。试试sns.lmplot("Length of Membership", "Yearly Amount Spent", customers)

标签: python pandas dataframe seaborn


【解决方案1】:

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

我传递的是 Series,而我应该传递的是字符串,例如:

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

【讨论】:

    猜你喜欢
    • 2014-07-17
    • 1970-01-01
    • 2019-08-29
    • 2018-12-25
    • 2017-09-09
    • 2019-06-20
    • 2018-02-28
    • 2020-08-23
    • 2020-06-29
    相关资源
    最近更新 更多