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
Post a Comment