Abhishek Rai
Abhishek Rai

Reputation: 13

Making data trend using python

I want to make data trending using python for a dataframe for eg my raw data in csv is below format

Date TCH_Nom TCH_Denom SD_Nom SD_Denom  

1/08/2018 42  58 4 21  
2/08/2018 67 100 12 120  
3/08/2018 23 451 9 34 

Output should be

KPI        1/08/2018 2/08/2018 3/08/2018  
TCH_Nom     42         67        23  
TCH_Denom   58         100       451  
SD_Nom       4         12         9  
SD_Denom     21        120       34

Upvotes: 1

Views: 172

Answers (1)

Bal Krishna Jha
Bal Krishna Jha

Reputation: 7206

from io import StringIO
import pandas as pd

txt = '''Date TCH_Nom TCH_Denom SD_Nom SD_Denom

1/08/2018 42 58 4 21
2/08/2018 67 100 12 120
3/08/2018 23 451 9 34'''
df = pd.read_table(StringIO(txt),sep = '\s+')

As pointed out in comment:

df.set_index('Date',inplace = True) # set index to Date column
df.T

which gives this outcome:

Date    1/08/2018   2/08/2018   3/08/2018
TCH_Nom 42  67  23
TCH_Denom   58  100 451
SD_Nom  4   12  9
SD_Denom    21  120 34

Upvotes: 1

Related Questions