您可以使用lreshape
与Series.plot
:
print (df)
Price Quantity Price Quantity Price Quantity
0 2 1 4 5 13 10
1 8 7 2 3 6 8
#remove duplicates in columns adding numbers
L = ['Price', 'Quantity']
k = int(len(df.columns)/2)
df.columns = ['{}{}'.format(x, y) for y in range(1, k+1) for x in L]
print (df)
Price1 Quantity1 Price2 Quantity2 Price3 Quantity3
0 2 1 4 5 13 10
1 8 7 2 3 6 8
#filter columns
prices = [col for col in df.columns if col.startswith('Price')]
quantities = [col for col in df.columns if col.startswith('Quantity')]
print (prices)
['Price1', 'Price2', 'Price3']
print (quantities)
['Quantity1', 'Quantity2', 'Quantity3']
#reshape all values to 2 columns
df = pd.lreshape(df, {'Price':prices, 'Quantity':quantities})
print (df)
Price Quantity
0 2 1
1 8 7
2 4 5
3 2 3
4 13 10
5 6 8
df.set_index('Price')['Quantity'].plot()
之前,我有overlaping线 - 我想要的东西 - 与此解决方案,它吸引他们依次 –
你能解释一下吗?因为看来我不明白你需要什么。 – jezrael
https://www.dropbox.com/s/c36una20ex0eh5l/Screenshot%202017-02-20%2012.33.11.png?dl=0这是我得到的图表。我所需要的是让垂直线水平。这些线条由两个具有我应该在上面的形状的数据框生成。 –