[英]Plot multiple rows of dataframe in pandas for specific columns
df df
SKU Comp Brand Jan_Sales Feb_Sales Mar_sales Apr_sales Dec_sales..
A AC BA 122 100 50 200 300
B BC BB 100 50 80 90 250
C CC BC 40 30 100 10 11
and so on等等
Now I want a graph which will plot Jan sales, feb sales and so on till dec in one line for SKU A, Similarly one line on the same graph for SKU B and same way for SKU C.现在我想要一个图表,它将在 SKU A 的一行中绘制 1 月的销售额、2 月的销售额等,直到 12 月,同样,SKU B 的同一图表上的一行和 SKU C 的相同方式。
I read few answers which say that I need to transpose my data.我读了几个答案,说我需要转置我的数据。 Something like below像下面这样
df.T. plot()
However my first column is SKU, and I want to plot based on that.然而,我的第一列是 SKU,我想以此为基础进行绘图。 Rest of the columns are numeric.其余的列是数字。 So I want that on each line SKU Name should be mentioned.所以我希望在每一行上都应该提到 SKU 名称。 And plotting should be row wise并且绘图应该是行明智的
EDIT(added after receiving some answers as I am facing this issue in few other datasets):编辑(在收到一些答案后添加,因为我在其他几个数据集中面临这个问题):
lets say I dont want columns Company, brand etc, then what to do假设我不想要列公司、品牌等,那么该怎么办
使用DataFrame.set_index
将SKU
转换为索引,然后转置:
df.set_index('SKU').T.plot()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.