【发布时间】:2021-09-20 19:45:04
【问题描述】:
我想调用pandas dataframe apply()函数返回两个变量
例如:
print(word_list)
['abc', 'lmn', ]
def is_related_content(x):
for y in word_list:
if y in x:
return x, y
return '', ''
print(df.head())
str1
abcdef
hijklmn
asddada
# call apply() function like this
df['string'], df['substring'] = df['str1'].apply(lambda x: is_related_content(x))
# it should be like this
print(df.head())
str1 string substring
abcdef abcdef abc
hijklmn hijklmn lmn
asddada None None
但我收到如下错误消息:
news_df['merge_' + col], news_df[col] = news_df['content'].fillna("").apply(lambda x: is_related_content(x))
ValueError:要解压的值太多(预期为 2)
谁能帮帮我?
提前致谢。
【问题讨论】: