原代码
对DataFram中的某一列进行修改,删除字符串空格后的内容。
for i in df.index:
df.at[i,'日期'] = df.at[i,'日期'].split(" ")[0]
警告说明
在使用pandas对DataFrame中的某一列进行修改赋值时给出如下警告:
Try using .loc[row_indexer,col_indexer] = value instead
处理方式
for i in df.index:
temp = df.at[i,'日期']
j = temp.find(' ')
if j > 6:
df.at[i,'日期'] = temp[0:j]
- 使用临时值存储字符串
- 使用.at进行赋值操作