简体   繁体   English

Pandas 时间戳列列读取红移时出现问题

[英]Pandas time stamp column column having issues reading to redshift

I have a dataframe that looks like this我有一个看起来像这样的数据框

d = {'Timestamp': ['Nov 16 10:39:54', 'Nov 16 10:39:54', 'Nov 16 10:39:54', 'Nov 16 10:39:54', 'Nov 16 10:40:17']}
df_sample = pd.DataFrame(data=d)
df_sample.head()

Redshift seems to throw an error when I try to load this into a table.当我尝试将其加载到表中时,Redshift 似乎会引发错误。 I get this error我收到这个错误

ProgrammingError: {'S': 'ERROR', 'C': '42601', 'M': 'syntax error at or near "Full"', 'P': '88', 'F': '/home/ec2-user/padb/src/pg/src/backend/parser/parser_scan.l', 'L': '732', 'R': 'yyerror'}

It could be a different column but nonetheless how would I convert this to a more normal datatime?它可能是一个不同的列,但我如何将其转换为更正常的数据时间?

You want

df_sample["iso8601"] = pd.to_datetime(
    "2022 " + df_sample.Timestamp, format="%Y %b %d %H:%M:%S"
)
print(df_sample.tail(3).set_index("iso8601"))

output输出

                           Timestamp
iso8601                             
2022-11-16 10:39:54  Nov 16 10:39:54
2022-11-16 10:39:54  Nov 16 10:39:54
2022-11-16 10:40:17  Nov 16 10:40:17

Take care to treat these as UTC timestamps, rather than times in some local timezone, as there is no zone information bundled along with that data.请注意将这些视为 UTC 时间戳,而不是某个本地时区的时间,因为没有与该数据捆绑在一起的区域信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM