如何将带有参数的方法传递给大熊猫?

时间:2019-02-20 02:58:22

标签: python pandas

以下按预期工作:

def genres_names (row):
  data = str(row['genres'])
  ...
  return ...

data_df['genres_names'] = data_df.apply(genres_names, axis=1)

概括地说,我想传递一个参数:

def names (row, column):
  data = str(row[column])
  ...
  return ...

data_df['genres_names'] = data_df.apply(names('genres'), axis=1)

这不起作用:

TypeError: names() missing 1 required positional argument: 'column'

传递column='genres'会加注

TypeError: genres_names() missing 1 required positional argument: 'row'

不确定如何访问该行...

0 个答案:

没有答案