【问题标题】:`TypeError: 'DataFrame' object is not callable` trying to make bar graph`TypeError:'DataFrame'对象不可调用`试图制作条形图
【发布时间】:2020-10-13 21:02:42
【问题描述】:

TypeError: 'DataFrame' 对象不可调用

data2('New_deaths', 'New_cases').head().plot.bar(title= "Statistics of 
New_deaths and New_cases by country")#bar graph

【问题讨论】:

    标签: python pandas dataframe typeerror


    【解决方案1】:

    这行得通吗?

    data2['New_deaths', 'New_cases'].head().plot.bar(title= "Statistics of New_deaths and New_cases by country")#bar graph
    

    这样,您不是在尝试调用数据框,而是在访问它。

    【讨论】:

      【解决方案2】:

      你的问题不清楚。所以,我根据我认为你想做的事情给出答案。 绘制一列数据框,代码如下:

      data2["New_deaths"].head().plot.bar(title= "Statistics of New_deaths and New_cases by country")
      

      或者

      import matplotlib.pyplot as plt
      
      fig, ax = plt.subplots()
      x = data2["New_deaths"].drop_duplicates()
      graph = ax.bar(x, data = data2["New_deaths"].head(), height= data2["New_deaths"].max() + 100, label="data")
      ax.set_title("Statistics of New_deaths and New_cases by country")
      plt.show()
      
      

      如果您尝试同时绘制数据框的两列,例如并排的栏,您可以查看:https://matplotlib.org/3.2.1/gallery/lines_bars_and_markers/barchart.html#sphx-glr-gallery-lines-bars-and-markers-barchart-py

      如果您尝试进行分组:

      data2.groupby(["New_deaths","New_cases"]).head().plot.bar(title= "Statistics of New_deaths and New_cases by country")
      

      pandas groupby 的链接:https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html

      【讨论】:

        猜你喜欢
        • 2021-08-23
        • 2017-06-17
        • 1970-01-01
        • 2014-02-05
        • 1970-01-01
        • 2021-09-20
        • 1970-01-01
        • 2019-05-28
        • 1970-01-01
        相关资源
        最近更新 更多