我有一个数据框,其中一列存储日期。你知道吗
但是,其中一些日期是格式正确的datetime对象,如'2018-12-24 17:00:00'
,而另一些则不是,并且存储为'20181225'
。你知道吗
当我尝试使用plotly绘制这些时,格式不正确的值变成了EPOCH日期,这是一个问题。你知道吗
有没有什么办法我可以得到一个数据帧的副本,只有那些行的日期格式正确?你知道吗
我试过用
clean_dict= dailySum_df.where(dailySum_df[isinstance(dailySum_df['time'],datetime.datetime)])
方法,但由于“Array conditional must be same shape as self”错误而无法工作。你知道吗
dailySum_df = pd.DataFrame(list(cursors['dailySum']))
trace = go.Scatter(
x=dailySum_df['time'],
y=dailySum_df['countMessageIn']
)
data = [trace]
py.plot(data, filename='basic-line')
尝试使用解析数据帧的dates列dateutil.parser.parse文件应用函数。你知道吗
应用
dateutil.parser
,另请参阅我的答案here:输入:
输出:
与Gustavo的解决方案不同,它可以处理没有可识别日期的行,并根据您的问题过滤掉这些行。你知道吗
如果原始时间列可能包含日期本身以外的其他文本,请包含
fuzzy=True
参数,如here所示。你知道吗相关问题 更多 >
编程相关推荐