Pandas warning:Try using .loc[row_indexer,col_indexer] = value instead

Original code

Modify a column in DataFram, delete the content after the string space.

for i in df.index:
        df.at[i,'日期'] = df.at[i,'日期'].split(" ")[0]

Warning note

When using pandas to modify and assign a column in a DataFrame, the following warning is given:
Try using .loc[row_indexer,col_indexer] = value instead

Processing method

for i in df.index:
    temp = df.at[i,'日期']
    j = temp.find(' ')
    if j > 6:
        df.at[i,'日期'] = temp[0:j] 
  • Use temporary values ​​to store strings
  • Use .at for assignment operation

Guess you like

Origin blog.csdn.net/u013894391/article/details/104520385