[英]pandas multiple dataframe plot
I have two data frames.我有两个数据框。 They have the same structure but they come from two different model.
它们具有相同的结构,但来自两个不同的 model。 Basically, I would like to compare them in order to find the differences.
基本上,我想比较它们以找出差异。 The first thing that I would like to do is to plot two rows, the first from the first data frames and the second from the other.
我想做的第一件事是 plot 两行,第一行来自第一个数据帧,第二行来自另一个。
This is what I do: I read the two csv file,这就是我所做的:我阅读了两个 csv 文件,
PRICES = pd.read_csv('test_model_1.csv',sep=';',index_col=0, header = 0)
PRICES_B = pd.read_csv('bench_mark.csv',sep=';',index_col=0, header = 0)
then I plot the 8th column of both, as:然后我 plot 两者的第 8 列,如:
rowM = PRICES.iloc[8]
rowB = PRICES_B.iloc[8]
rowM.plot()
rowB.plot()
It does not seem the correct way.这似乎不是正确的方法。 Indeed, I am not able to choose the labels or the legends.
确实,我无法选择标签或图例。
This the results: comparison between the 8th row of the first dataframe and the 8th row of the second dataframe结果如下:第一个 dataframe 的第 8 行和第二个 dataframe 的第 8 行之间的比较
Someone could suggest me the correct way to compare the two data frames and plot some of the selected columns?有人可以建议我比较两个数据框和 plot 某些选定列的正确方法吗?
lets prepare some test data:让我们准备一些测试数据:
mtx1 = np.random.rand(10,8)*1.1+2
mtx2 = np.random.rand(10,8)+2
df1 = pd.DataFrame(mtx1)
df2 = pd.DataFrame(mtx2)
example output for df1: df1 的示例 output:
Out[60]:
0 1 2 3
0 2.604748 2.233979 2.575730 2.491230
1 3.005079 2.984622 2.745642 2.082218
2 2.577554 3.001736 2.560687 2.838092
3 2.342114 2.435438 2.449978 2.984128
4 2.416953 2.124780 2.476963 2.766410
5 2.468492 2.662972 2.975939 3.026482
6 2.738153 3.024694 2.916784 2.988288
7 2.082538 3.030582 2.959201 2.438686
8 2.917811 2.798586 2.648060 2.991314
9 2.133571 2.162194 2.085843 2.927913
now let's plot it:现在让我们 plot 吧:
import matplotlib.pyplot as plt
%matplotlib inline
i = range(0,len(df1.loc[6,:])) # from 0 to 3
plt.plot(i,df1.loc[6,:]) # take whole row 6
plt.plot(i,df2.loc[6,:]) # take whole row 6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.