【问题标题】:How to plot graph for the output keeping first col as labels and 2nd col as values如何为输出绘制图形,将第一列作为标签,将第二列作为值
【发布时间】:2020-10-03 10:21:42
【问题描述】:
x2 = x1.head(10)
x2

output:
374661.0    15942
313131.0    11796
296016.0    10190
267708.0     9246
306726.0     5556
321531.0     4982
307566.0     4132
274869.0     3714
278523.0     3344
300258.0     3280
Name: UserId, dtype: int64

【问题讨论】:

  • 请指定您需要的绘图类型(条形图、直方图、散点图..)。并添加您尝试过的内容..

标签: python pandas matplotlib data-science


【解决方案1】:

这是条形图的代码:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_clipboard()
df.columns = ['labels','values']

print(df)
plt.bar(df['labels'].astype(str),df['values'])
plt.show()

输出:

【讨论】:

  • 不使用剪贴板可以绘制图表吗?我的意思是剪贴板最近复制的项目必须是数据。是否可以将输出转换为新数据集?
  • 是的!是的!这就是你必须做的。相反,请使用您自己的数据框。
猜你喜欢
  • 2021-05-19
  • 2013-03-28
  • 1970-01-01
  • 1970-01-01
  • 2020-05-21
  • 1970-01-01
  • 2020-03-08
  • 2018-11-20
  • 1970-01-01
相关资源
最近更新 更多