(1)<ipython-input-29-689d63a5415c>:1: DtypeWarning: Columns (7,9) have mixed types.Specify dtype option on import or set low_memory=False.
解决:df = pd.read_csv(path, encoding='gbk', low_memory=False)
(2)将datetime64[ns]索引转换为datepandas进行比较
转载:https://www.5axxw.com/questions/content/41ox3m
以下python代码:
current_ts = datetime.datetime.now()
current_date = current_ts.date()
new_df = df[df.index >= current_date]
df.index
是一个datetime64[ns],当我运行代码时,我得到Invalid comparison between dtype=datetime64[ns] and date
。
如何将索引转换为日期以便进行比较?
解决:Pandas datetime64[ns]
不能直接与datetime.date
相比。需要转换:
df[df.index >= pd.Timestamp(current_date)]