【发布时间】:2022-10-14 23:24:17
【问题描述】:
我有很多列要应用相同的功能。
cols=['a','b','c','d']
def cols_1(x):
if x[c]=="5: Very important":
return 5
if x[c]== "1: Not at all important":
return 1
else:
return x
for c in cols:
df[c]=df[c].apply(cols_1)
我已经尝试了上述的许多变体,但没有一个有效。我究竟做错了什么?
【问题讨论】: