【发布时间】:2020-03-10 14:36:41
【问题描述】:
下面的伪代码需要使用 lambda & apply。我对实现它的 else 部分感到震惊,并在 DF 上循环并在遇到更多语法问题时创建一个新的。
提前致谢。
DataFrame [df]
a b c d e f
100 10 1 www qqq 1/1/2020
200 20 2 eee rrr 2/1/2020
300 30 3 ttt yyy 3/1/2020
400 40 4 uuu iii 4/1/2020
500 50 5 ooo ppp 5/1/2020
def func(x,y):
for i, r in df.iterrows():
df_new = df[df['a'].isin(x)]
if df['b'] <= y:
df_new['newcolumn1'] = df['b']
df_new['newcolumn2'] = df['c']
df_new['newcolumn3'] = df['d']
df_new['newcolumn4'] = df['e']
df_new['newcolumn5'] = df['f']
df_new['newcolumn6'] = y - df['b']
else:
continue
return df;
【问题讨论】:
标签: python pandas lambda apply