import pandas as pd
data = pd.read_excel("data.xlsx", engine="openpyxl")
result = data.copy()
f = pd.read_excel("feeding.xlsx")
m = pd.read_excel("motility.xlsx")
t = pd.read_excel("tiering.xlsx")
length_num = data.shape[0]
def search(ex:pd.DataFrame, content:str) -> None:
pbdb = list(zip(list(ex['pbdb']),list(ex['change'])))
for row in pbdb:
if content == str(row[0]):
return str(row[1])
break
else:
continue
for i in range(length_num):
df = data.iloc[i]
new = df.copy()
new['Motility'] = search(m, df['motility_'])
new['Feeding'] = search(f, df['diet'])
new['Tiering'] = search(t, df['life_habit'])
result.iloc[i] = new
result.to_excel("result.xlsx")
使用Python遍历excel每一行并对指定列进行修改
于 2024-01-22 12:38:47 首次发布
![](https://img-home.csdnimg.cn/images/20240611030827.png)