A value is trying to be set on a copy of a slice from a DataFrame解决方案
使用pandas 的时候 会用到 DataFrame 数据进行时间格式化转换
报错信息 下会接着 报错代码
仔细查知道
代码:代码中使用的to_datetime字符串转时间的格式
但是由于要使用loc的方法所以 DataFrame对象 excle要求使用copy 否则会报错
使用DataFrame对象对象前,先copy一下就行了.正确代码如下
def excel_to_date(excel,t_colum):
excel=excel.copy()
for i in range(len(excel)):
excel.loc[i, t_colum]=pd.to_datetime(excel.loc[i, t_colum])
return excel
特别说明:
loc 根据名称来取 iloc 更加索引来取 但是当DataFrame对象不指定名称的时候
默认索引加列名取值,默认情况下,感觉loc和iloc感觉都差不多.个人水平有限,如果有错误希望指正.