转换为数据类型(在csv文件中)
(yyyy-mm-dd h:mm:ss(当前列数据类型)-(转换)-> 143141231(纳秒))
问题
->对象与格式'%Y-%m-%d %H:%M:%S'
csv文件
例如)
时间
2019-01-01 0:00:00
2019-01-01 8:50:00
2019-01-01 8:50:00
2019-01-01 8:51:00
2019-01-01 8:51:00
2019-01-01 8:51:00
代码
import time
import datetime
import pandas as pd
df = pd.read_csv("data/test.csv")
df.head()
mydate =str(df["time"])
timestamp = time.mktime(datetime.datetime.strptime(mydate, "%Y-%m-%d %H:%M:%S").timetuple())
df["time"] = [str(df[timestamp()][t]) for t in range(len(df))]
df.head()
ns_precision = df
ns_precision.to_csv("data/test_convert.csv", index=False)
期待
时间
1131314141
1412313131
1312414123
1231225244
2421412141
结果
ValueError: time data '0
2019-01-01 0:00:00\n1 ... 2019-01-30 20:15:00\n
Name: time, Length: 77876,
dtype: object' does not match format '%Y-%m-%d %H:%M:%S'