Python Pandas`read\u json`函数将字符串转换为DateTime对象,即使指定了`convert\u dates=False`attr
我有下一个问题:Python Pandas`read\u json`函数将字符串转换为DateTime对象,即使指定了`convert\u dates=False`attr,python,json,python-3.x,pandas,jupyter-notebook,Python,Json,Python 3.x,Pandas,Jupyter Notebook,我有下一个问题: [{ "2016-08": 1355, "2016-09": 2799, "2016-10": 2432, "2016-11": 0 }, { "2016-08": 1475, "2016-09": 1968, "2016-10": 1375, "2016-11": 0 }, { "2016-08": 3097, "2016-09": 1244, "2016-10": 2339, "2016-11": 0 }, { "2016-08": 1305, "2016-09": 162
[{
"2016-08": 1355,
"2016-09": 2799,
"2016-10": 2432,
"2016-11": 0
}, {
"2016-08": 1475,
"2016-09": 1968,
"2016-10": 1375,
"2016-11": 0
}, {
"2016-08": 3097,
"2016-09": 1244,
"2016-10": 2339,
"2016-11": 0
}, {
"2016-08": 1305,
"2016-09": 1625,
"2016-10": 3038,
"2016-11": 0
}, {
"2016-08": 1530,
"2016-09": 4385,
"2016-10": 2369,
"2016-11": 0
}, {
"2016-08": 3515,
"2016-09": 4532,
"2016-10": 2497,
"2016-11": 0
}, {
"2016-08": 1539,
"2016-09": 1276,
"2016-10": 4378,
"2016-11": 0
}, {
"2016-08": 4989,
"2016-09": 3143,
"2016-10": 2075,
"2016-11": 0
}, {
"2016-08": 3357,
"2016-09": 2745,
"2016-10": 1592,
"2016-11": 0
}, {
"2016-08": 3224,
"2016-09": 2694,
"2016-10": 3958,
"2016-11": 0
}]
当我调用pandas.read_json(json,convert_dates=False)时,我得到下一个结果:
如您所见,所有列都已自动转换。我用错了什么
我一直在使用python3.5和pandas 0.18.1您需要参数
convert\u axes=False
:
如果值未转换为索引
或列
,则转换日期=False有效:
[{
"2016-08": "2016-08",
"2016-09": 2799,
"2016-10": 2432,
"2016-11": 0
}, {
"2016-08": 1475,
"2016-09": 1968,
"2016-10": 1375,
"2016-11": 0
},
...
...
#1355 changed to '2016-08'
df = pd.read_json('file.json', convert_dates=False)
print (df)
2016-08-01 2016-09-01 2016-10-01 2016-11-01
0 2016-08 2799 2432 0
1 1475 1968 1375 0
2 3097 1244 2339 0
3 1305 1625 3038 0
4 1530 4385 2369 0
5 3515 4532 2497 0
6 1539 1276 4378 0
7 4989 3143 2075 0
8 3357 2745 1592 0
9 3224 2694 3958 0
如果同时使用两个参数:
df = pd.read_json('file.json', convert_dates=False, convert_axes=False)
print (df)
2016-08 2016-09 2016-10 2016-11
0 2016-08 2799 2432 0
1 1475 1968 1375 0
2 3097 1244 2339 0
3 1305 1625 3038 0
4 1530 4385 2369 0
5 3515 4532 2497 0
6 1539 1276 4378 0
7 4989 3143 2075 0
8 3357 2745 1592 0
9 3224 2694 3958 0
df = pd.read_json('file.json', convert_dates=False, convert_axes=False)
print (df)
2016-08 2016-09 2016-10 2016-11
0 2016-08 2799 2432 0
1 1475 1968 1375 0
2 3097 1244 2339 0
3 1305 1625 3038 0
4 1530 4385 2369 0
5 3515 4532 2497 0
6 1539 1276 4378 0
7 4989 3143 2075 0
8 3357 2745 1592 0
9 3224 2694 3958 0