如何在 Seaborn lmplot 中使用 pandas DataFrame 作为数据参数
How to use a pandas DataFrame as data parameter in Seaborn lmplot
查看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 数据帧转换为整洁的 ("long-form") 数据帧以用于 lmplot
?
目前,我正在尝试执行以下操作:
sns.lmplot(customers["Length of Membership"], customers["Yearly Amount Spent"], customers)
(Seaborn 导入为 sns
)。上面的 python 代码 returns 包含一个很长的浮点列表的错误。
感谢 Bob Haffner,仔细查看文档,DataFrame 根本不是问题,而是我传递的 X 和 Y 参数。
我传递的是 Series,而我本应传递的是字符串,例如:
sns.lmplot("Length of Membership", "Yearly Amount Spent", customers)
查看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 数据帧转换为整洁的 ("long-form") 数据帧以用于 lmplot
?
目前,我正在尝试执行以下操作:
sns.lmplot(customers["Length of Membership"], customers["Yearly Amount Spent"], customers)
(Seaborn 导入为 sns
)。上面的 python 代码 returns 包含一个很长的浮点列表的错误。
感谢 Bob Haffner,仔细查看文档,DataFrame 根本不是问题,而是我传递的 X 和 Y 参数。
我传递的是 Series,而我本应传递的是字符串,例如:
sns.lmplot("Length of Membership", "Yearly Amount Spent", customers)