Series中修改value的值 1. 按列修改 注:如果是object(即字符串类型),可以直接使用.str来对字符串的进行修改,然后除去修改字符串,可以直接使用等式来进行修改 # 在体重和脑重量两列,将 ! 替换为 . 为什么会有这种操作的方法的呢 df_clean['Body weight (kg)'] = df_clean['Body weight (kg)'].str.replace('!', '.') df_clean['Brain weight (g)'] = df_clean['Brain weight (g)'].str.replace('!', '.') 通过构建Series来修改Series列 after = [] for x in df_clean['Body weight (kg)']: #遍历一列中的所有并执行操作 print(x.replace("!",'.')) print(df_clean.Animal.values) after.append(x.replace("!",'.')) print(after) df_clean['Body weight (kg)'] = pd.Series(after) #把新生成的Series赋值给原来的 2. 按列中的值修改 使用index来选中进行修改 df.columnName.indexName= "hello" #通过直接使用索引来选中进行修改 通过df.loc / df.iloc 选中后通过等号赋值修改 详情看官方示例iloc http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.iloc.html?highlight=iloc#pandas.DataFrame.ilocloc 官方详情 http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.loc.html?highlight=loc#pandas.DataFrame.loc