I'm new to pandas and trying to learn and ran into this problem. I've a dataframe and I am trying to plot the rows of the dataframe for each index value. I want different plots (subplots) for each index in the dataframe.
ANDAMAN & NICOBAR ISLANDS 264296 32413 80984 1286 338 31 564 669
ARUNACHAL PRADESH 401876 27045 418732 3287 162815 771 362553 6648
CHANDIGARH 852574 51447 8720 138329 1160 1960 246 1014
Here the string values are the indexes and i want different plots for these indexes of the dataframe. How can it be done?
I think you you need is T
for transpose and plot
with parameter subplots=True
:
print(df)
Output:
1 2 3 4 5 6 7 8
0
ANDAMAN & NICOBAR ISLANDS 264296 32413 80984 1286 338 31 564 669
ARUNACHAL PRADESH 401876 27045 418732 3287 162815 771 362553 6648
CHANDIGARH 852574 51447 8720 138329 1160 1960 246 1014
Where column 0 is in your index which contains locations.
The use df.T to transpose the dataframe in to a "column" format vs "rows".
df.T
Output:
0 ANDAMAN & NICOBAR ISLANDS ARUNACHAL PRADESH CHANDIGARH
1 264296 401876 852574
2 32413 27045 51447
3 80984 418732 8720
4 1286 3287 138329
5 338 162815 1160
6 31 771 1960
7 564 362553 246
8 669 6648 1014
And, now let's generate plots:
df.T.plot(subplots=True)
Output: