【问题标题】:Seaborn scatterplot from a pandas dataframe for 2 columns来自 pandas 数据框的 2 列的 Seaborn 散点图
【发布时间】:2020-05-14 03:51:28
【问题描述】:

我有一个数据框 df:

sentiment | topic
1         | 1
-4        | 0
2         | 1
-1        | 0
1         | 0
3         | 1

我想制作一个散点图,看看情绪值如何根据主题排列。

我的代码:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df = pd.read_sql_table("df", result)
sns.catplot(x="topic", y="sentiment", order=["0", "1"], data=df)
plt.show()

但剧情是空的?

Seaborn 是否无法正确地从数据框中获取值?

【问题讨论】:

    标签: pandas seaborn scatter-plot


    【解决方案1】:

    如果没有原始数据,很难确切知道问题出在哪里,但在您提供的表格中,topic 列中的值似乎是数字,而不是字符串。如果是这种情况,那么您不应该将字符串传递给 order 参数。如果这是问题所在,这应该可行:

    sns.catplot(x="topic", y="sentiment", order=[0, 1], data=df)
    plt.show()
    

    如果这仍然不起作用,您可以尝试完全删除 order 参数,看看是否可以解决问题。

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 2020-01-19
      • 2016-02-01
      • 1970-01-01
      • 2019-05-16
      • 2017-05-16
      • 1970-01-01
      • 2015-05-28
      相关资源
      最近更新 更多