如何停止Pandas Dataframe read_json方法将我的纪元转换为人类可读的字符串

时间:2016-09-05 12:10:49

标签: json string datetime pandas dataframe

我使用to_json方法来序列化我的数据帧,内容如下所示:

"1467065160244362165":"1985.875","1467065161029130301":"1985.875","1467065161481601498":"1985.875","1467065161486508221":"1985.875"

如何停止read_json方法将我的纪元值从1467065160244362165转换为2016-06-28 06:57:23.786726222之类的内容。 这就是我调用read_json的方式:

data = pd.read_json(remote_result_fullpath, convert_dates=False)

1 个答案:

答案 0 :(得分:4)

对我而言:

import pandas as pd

#added {} to file
remote_result_fullpath = 'https://dl.dropboxusercontent.com/u/84444599/file.json'

data = pd.read_json(remote_result_fullpath, 
                    convert_dates=False, #dont convert columns to dates 
                    convert_axes=False, #dont convert index to dates
                    typ='series') #if need convert output to Series

print (data)
1467065160244362165    1985.875
1467065161029130301    1985.875
1467065161481601498    1985.875
1467065161486508221    1985.875

print (data.dtypes)
dtype: float64
float64

如果需要字符串添加dtype

data = pd.read_json(remote_result_fullpath, 
                    convert_dates=False, 
                    convert_axes=False,
                    typ='series',
                    dtype='object')

print (data)
1467065160244362165    1985.875
1467065161029130301    1985.875
1467065161481601498    1985.875
1467065161486508221    1985.875

print (data.dtypes)
dtype: object
object

print (data.index)
Index(['1467065160244362165', '1467065161029130301', '1467065161481601498',
       '1467065161486508221'],
      dtype='object')