python - Cast types on the fly while creating dataframe -


i have kind of partial json object, dict:

{     u'20140816 00': {u'var': u'40.78'},     u'20140816 01': {u'var': u'53.24'},     u'20140816 02': {u'var': u'50.23'},     ... } 

and want put in pandas dataframe.

however, change keys string datetime (datetime.strptime(key, '%y%m%d %h') , cast var value string float.

is possible while creating pandas dataframe, or if not easiest way recast types json object pandas dataframe.

you can use convert_objects method convert strings desired dtypes.

normally read_ methods have date handling param , these can handle formats.

in case, seeing convert_objects doesn't quite want can call pandas method to_datetime convert column so:

df['time_col'] = pd.to_datetime(df['time_col']) 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -