2014-01-31 96 views

回答

5

也許你可以將DataFrame轉置。

用10列和5行創建一個DataFrame。

 
In [1]: import pandas as pd 
In [2]: import numpy as np 
In [3]: df = pd.DataFrame(np.random.rand(5,10)) 
In [4]: df 
Out[4]: 
      0   1   2   3   4   5   6 \ 
0 0.221466 0.375541 0.318416 0.695447 0.117332 0.836268 0.326673 
1 0.439128 0.546087 0.380608 0.599192 0.553365 0.739253 0.984701 
2 0.189311 0.799067 0.322041 0.171035 0.595848 0.106069 0.940712 
3 0.971887 0.416420 0.945873 0.828611 0.055950 0.690107 0.526104 
4 0.643041 0.800376 0.010879 0.677169 0.268208 0.151503 0.062268 

      7   8   9 
0 0.690805 0.741308 0.487934 
1 0.827711 0.284417 0.878259 
2 0.734911 0.597626 0.256107 
3 0.583156 0.398342 0.406590 
4 0.247892 0.990469 0.611637 

In [8]: df.plot() 

enter image description here

 
In [9]: df.T.plot() 

enter image description here

以下是轉置數據幀中的內容。

 
In [10]: df.T 
Out[10]: 
      0   1   2   3   4 
0 0.221466 0.439128 0.189311 0.971887 0.643041 
1 0.375541 0.546087 0.799067 0.416420 0.800376 
2 0.318416 0.380608 0.322041 0.945873 0.010879 
3 0.695447 0.599192 0.171035 0.828611 0.677169 
4 0.117332 0.553365 0.595848 0.055950 0.268208 
5 0.836268 0.739253 0.106069 0.690107 0.151503 
6 0.326673 0.984701 0.940712 0.526104 0.062268 
7 0.690805 0.827711 0.734911 0.583156 0.247892 
8 0.741308 0.284417 0.597626 0.398342 0.990469 
9 0.487934 0.878259 0.256107 0.406590 0.611637 
+0

謝謝。現在這很明顯。 – JAB

相關問題