2016-08-17 1 views
1

Iは、CO-RHという列と、対応する温度値を持つデータセットを有する:elif関数をグラフでどのように実行するのですか?

import pandas as pd 
df=pd.read_csv('F:/data32.csv',parse_dates=['Date']) 
print (df) 
Temperature  unit  unit.1  CO2 flux.1 %Root Resp  CO2-Rh 
4.5    umol/m2/s mg/cm^2/h 0.001210  26.5 0.000889 
4.5    umol/m2/s mg/cm^2/h 0.001339  26.5 0.000984 
6.5    umol/m2/s mg/cm^2/h 0.001339  26.5 0.000984 
5.3    umol/m2/s mg/cm^2/h 0.001469  26.5 0.001080 
4.0    umol/m2/s mg/cm^2/h 0.001598  26.5 0.001175 
5.5    umol/m2/s mg/cm^2/h 0.001598  26.5 0.001175 
5.0    umol/m2/s mg/cm^2/h 0.001771  26.5 0.001302 
5.0    umol/m2/s mg/cm^2/h 0.001944  26.5 0.001429 
4.5    umol/m2/s mg/cm^2/h 0.003110  26.5 0.002286 
10.3   umol/m2/s mg/cm^2/h 0.001166  26.5 0.000857 
9.0    umol/m2/s mg/cm^2/h 0.002030  26.5 0.001492 

IはCO2-RHという列と、対応する温度値を持つデータセットを持っています。私は、私のデータセットを平均気温に応じて分割するように指示したいと思います。温度が8.21を超えている場合は、データセット「a」に、8.21以下のデータは「a」に、データセット "b"(これは2つの別々のグラフをプロットする最良の方法だと思います)。私に何ができる? これまでのところ私が得たものです。

if df['Temperature']> 8.212312312312307: 
    plt.plot(df['Temperature'],df['CO2-rh'],linewidth=3) 
    plt.show() 

答えて

1

それはDataFrame.plotに必要boolean indexingのようになります。

import matplotlib.pyplot as plt 

mask = df['Temperature']> 8.212312312312307 

df1 = df[mask] 
df2 = df[~mask] 
print (df1) 
    Temperature  unit  unit.1 CO2 flux.1 %Root Resp CO2-Rh 
9   10.3 umol/m2/s mg/cm^2/h 0.001166  26.5 0.000857 
10   9.0 umol/m2/s mg/cm^2/h 0.002030  26.5 0.001492 

print (df2) 
    Temperature  unit  unit.1 CO2 flux.1 %Root Resp CO2-Rh 
0   4.5 umol/m2/s mg/cm^2/h 0.001210  26.5 0.000889 
1   4.5 umol/m2/s mg/cm^2/h 0.001339  26.5 0.000984 
2   6.5 umol/m2/s mg/cm^2/h 0.001339  26.5 0.000984 
3   5.3 umol/m2/s mg/cm^2/h 0.001469  26.5 0.001080 
4   4.0 umol/m2/s mg/cm^2/h 0.001598  26.5 0.001175 
5   5.5 umol/m2/s mg/cm^2/h 0.001598  26.5 0.001175 
6   5.0 umol/m2/s mg/cm^2/h 0.001771  26.5 0.001302 
7   5.0 umol/m2/s mg/cm^2/h 0.001944  26.5 0.001429 
8   4.5 umol/m2/s mg/cm^2/h 0.003110  26.5 0.002286 


df1[['Temperature','CO2-Rh']].plot(linewidth=3) 
df2[['Temperature','CO2-Rh']].plot(linewidth=3) 
plt.show() 
関連する問題