我正在使用以下代码将带有时间戳的数据帧转换为字符串:
df = pd.DataFrame.from_dict({ 'sentencess' : sentencess, 'publishedAts' : publishedAts, 'hasil_sentimens' : hasil_sentimens })
df['publishedAts'] = df['publishedAts'].apply(lambda x: x.dt.strftime('%Y/%m/%d'))
但我发现了错误:AttributeError:'str'对象没有属性'dt'
尝试使用:
实际上,在默认情况下,
pd.to_datetime
会给出YYYY-MM-DD
,因此如果您同意,可以使用:相关问题 更多 >
编程相关推荐