2017-12-05 10 views
0

私はインドで乳生産のデータセットを持っています。私はパンダで過去3年間にミルク生産量が増加した5州(もしあれば)のリストを取得しようとしています。パンダ - 異なる列の行の増加トレンドを検索

State  Total10-11 Total11-12 Total13-14 Total14-15 Total15-16 
Andhra Pradesh 11204  12088  13007   9656  10817 
Arunachal Pradesh 28   22   43   46   50 
Assam    790  797   814   829  844 
Bihar    6517  6643  7197   7775  8289 
Chhattisgarh  1030  1118  1208   1232  1278 
Goa     60   60   68   66   54 
Gujarat   9322  4089  11112  11690  12262 
Haryana   6268  6661  7442   7902  8381 
Himachal Pradesh 1102  1120  1151   1173  1283 

予想される出力:

State 
Assam 
Bihar 
Chhattisgarh 
Haryana 
Himachal Pradesh 

私は、毎年彼らの牛乳生産の増加傾向を持っている状態を見つけたいです。結果として、ミルクの生産量は前年比で減少してはならない。期待される出力状態は生産量が増加しており、生産に一度も浸漬はない。私はこの問題に悩まされていますが、いくつかの方法を試しましたが、正しい答えに近いものではありません。解決策は何ですか?前もって感謝します。

+0

あなたの努力、そしてあなたがより多くのclairtyのために期待しているが出力されます。 – Dark

+0

ここでトレンドを上げることはどういう意味ですか? – Dark

+0

総牛乳生産量が毎年増えている(結果的に減少することなく)。例:Arunachal Pradesh、Assamと同様、毎年乳生産量が増加しています。 –

答えて

1

あなたはいつもあなたが使用することができます増加しているの違いを探しているならdiff > 0cumsumすなわち

df = df.set_index("State/UT Name") 

temp = (df.T.diff() > 0).cumsum() 
# Values will increment if the difference between past and present is positive 
State/UT Name Andhra Pradesh Arunachal Pradesh Assam Bihar Chhattisgarh \ 
Total10-11     0     0  0  0    0 
Total11-12     1     0  1  1    1 
Total13-14     2     1  2  2    2 
Total14-15     2     2  3  3    3 
Total15-16     3     3  4  4    4 

State/UT Name Goa Gujarat Haryana Himachal Pradesh 
Total10-11  0  0  0     0 
Total11-12  0  0  1     1 
Total13-14  1  1  2     2 
Total14-15  1  2  3     3 
Total15-16  1  3  4     4 

# The one with max sum is the one that kept increasing over time 
temp.sum().nlargest(10) 

State/UT Name 
Assam    10 
Bihar    10 
Chhattisgarh   10 
Haryana    10 
Himachal Pradesh  10 
Andhra Pradesh  8 
Arunachal Pradesh  6 
Gujarat    6 
Goa     3 

あなたは状態名をしたい場合は、

states = temp.sum().nlargest(5).index.tolist() 

['Assam', 'Bihar', 'Chhattisgarh', 'Haryana', 'Himachal_Pradesh'] 
+0

明らかに、私は1年で生産が減少していない州名を探していて、それは前年に比べて増加しているだけです。 –

+0

インデックスはあなたの州名です – Dark

+0

@SrinidhiPatilあなたが私が何をしたのか理解してくれることを望みます。これは私のアプローチです。良いものがあるかもしれない – Dark

2

トレンドを探しているだけなら、私は視覚化が答えだと思います。

あなたはこのようなことをすることができます。 enter image description here

それとも

import matplotlib.pyplot as plt 
import pandas as pd 

df = df.set_index('state') 
df.T.plot(figsize=(10,15)) 

は個別にそれらを見て:

df.T.plot(figsize=(15,20), subplots=True,layout=(3,3)) 

enter image description here

関連する問題