python - Timestamp index for pandas dataframe from read_json() -


i'm reading single json line file data.json content:

[   {     "timestamp": 1436266865,     "rates": {       "eur": 0.911228,       "jpy": 122.5463,       "aud": 1.346118     }   },   {     "timestamp": 1436277661,     "rates": {       "jpy": 122.4789,       "aud": 1.348871,       "eur": 0.91433     }   } ] 

into pandas dataframe. want use "timestamp" dataframe's index. achieve by:

df = pandas.read_json('data.json') df.index = df['timestamp'] df.drop('timestamp', axis=1, inplace=1) 

is possible in 1 line?

import pandas pd  df = pd.read_json('data.json') df.set_index('timestamp',inplace=true) print(df) 

what set timestamp index. inplace=true prevent having df=df.set_index('timestamp') , default it'll drop column.

                                                        rates timestamp                                                     1436266865  {'eur': 0.9112279999999999, 'jpy': 122.5463, '... 1436277661  {'jpy': 122.4789, 'aud': 1.348871, 'eur': 0.91... 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -