【问题标题】:DataFrame constructor not properly called! matplotlib.pyplot error未正确调用 DataFrame 构造函数! matplotlib.pyplot 错误
【发布时间】:2018-11-02 05:05:01
【问题描述】:

尝试制作与宋飞传相关的剧集的 IMDB 评分散点图

这是我的代码:

df = pd.DataFrame({'Season_list'[1:], 'imdbRating_list'[1:]})
df.columns = ['Season', 'imdbRating']

df.plot.scatter(x = 'Season', y='imdbRating')

我不断收到此错误:

DataFrame constructor not properly called!

【问题讨论】:

    标签: python pandas matplotlib data-visualization


    【解决方案1】:

    您正在尝试从两个字符串{'eason_list', 'mdbRating_list'} 创建一个DataFrame。这是因为"Text"[1:] 选择除了字符串的第一个字符"Text"[1:] == "ext" 之外的所有字符。

    但是不能从这样的集合中创建 DataFrame。相反,您可能想要使用字典。字典由键、值对、{key1 : value1, key2 : value2} 创建。

    在这种情况下,我可以想象你有两个列表,ab,这样

    a = [1,2,3]
    b = [4,5,6]
    df = pd.DataFrame({'Season' : a[1:], 'imdbRating' : b[1:]})
    

    这将导致数据帧

       Season  imdbRating
    0       2           5
    1       3           6
    

    【讨论】:

      猜你喜欢
      • 2014-10-25
      • 2021-06-04
      • 1970-01-01
      • 2017-07-27
      • 2019-02-11
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      相关资源
      最近更新 更多