python - 对象不匹配格式 '%Y-%m-%d %H:%M:%S
问题描述
转换为数据类型(在 csv 文件中)
(yyyy-mm-dd h:mm:ss(当前列数据类型)--(转换)--> 143141231(纳秒))
问题 -> 对象与格式不匹配'%Y-%m-%d %H:%M:%S'
csv 文件
ex)
时间
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 2019-01-01
8:51:00 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'
解决方案
推荐阅读
- c# - 应用迁移时出现关系错误 - EF Core 5.0
- php - 使用 make:form 实时检索 Symfony 表单中的输入
- ethereum - 为什么我的 Solidity 以太坊合约的 gas 用完了?
- azure-devops - Azure Devops yaml - 如何转义换行符?
- python - 连接语句中 Flux 脚本面临的问题
- javascript - 类型错误:
不是构造函数,但之前已经使用过 - java - 在 JavaFx 中更改扩展的标题窗格背景
- javascript - SyntaxError: 不能在模块外使用 import 语句——jspdf
- google-sheets - 在谷歌表格中记录传感器数据
- silverlight - 使用 JMeter 记录 Silverlight 应用程序