【发布时间】:2019-01-08 07:27:11
【问题描述】:
我想知道如何让键成为列标题(结果、IP、时间)?
CSV 中的数据如下所示:
"Result":"Success","IP":"0.0.0.0","time":"2018-08-20T12:00:00.000Z"
"Result":"Failure","IP":"1.1.1.1","time":"2018-08-20T12:01:00.000Z"
我想这样格式化:
Result IP time
Success 0.0.0.0 2018-08-20T12:00:00.000Z
Failure 1.1.1.1 2018-08-20T12:01:00.000Z
到目前为止我的代码:
import pandas as pd
file = pd.read_csv("path_to.csv", sep='\n', names = ["Result","IP","time"])
df = pd.DataFrame(file)
print(df.head(1))
【问题讨论】: