每当我将 dataFrame 转换为_json 时,任何日期格式都会更改为“纪元时间”
[{"idNo":1234567891012,"姓名":"Jack","genderType":"男","日期":1544572800000,"branchName":"NY","location":"loc1 ","pCode":123}]
原来的日期是
日期:2018-12-12
我的Python代码
@app.route("/fileviewer/" , methods=["GET" , "POST"])
def fileviewer(name):
dest = (file_destination)
df = pd.read_excel(dest)
print(df)
x1=df.to_json(orient ='records')
print(x1)
render_template('fileviewer.html',x=df.to_html())
return render_template('fileviewer.html',x=x1)
df
打印效果良好
x1
打印“纪元时间”
最佳答案
您可以使用选项date_format
更改格式:
>>> df = pandas.DataFrame([
{'A' : 0, 't' : datetime.datetime(2018, 1, 2)},
{'A' : 1, 't' : datetime.datetime(2018, 1, 5)},
{'A' : 2, 't' : datetime.datetime(2018, 1, 7)}
])
>>> df.to_json(date_format = 'iso')
'{"A":{"0":0,"1":1,"2":2},"t":{"0":"2018-01-02T00:00:00.000Z","1":"2018-01-05T00:00:00.000Z","2":"2018-01-07T00:00:00.000Z"}}'
关于python - pandas to_json 将日期格式更改为 "epoch time",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53603857/