3
私はPandasデータフレームの列全体に関数を適用したいと考えています。この関数は、その列に、現在のデータを上書きするが、説明するために、次のことに別の列の値が必要になります。Python Pandasの引数として別の列を取る列に関数を適用する
df[1] = df.apply(retrieve_original_string(df[0]), axis=1)
:
col 0, col 1,
23, 'word'
45, 'word2'
63, 'word3'
私はパンダに番号欄に疲れて渡してきた方法を適用します
しかし、これはエラーをスローします:
sys:1: DtypeWarning: Columns (3,4) have mixed types. Specify dtype option on import or set low_memory=False.
Traceback (most recent call last):
File "/home/noname365/similar_keywords_microsoft/similar_keywords.py", line 95, in <module>
merged_df[1] = merged_df.apply(retrieve_original_string(merged_df[0], match_df), axis=1)
File "/home/noname365/similar_keywords_microsoft/similar_keywords.py", line 12, in retrieve_original_string
row_num = int(row)
File "/home/noname365/virtualenvs/env35/lib/python3.5/site-packages/pandas/core/series.py", line 81, in wrapper
"cannot convert the series to {0}".format(str(converter)))
TypeError: cannot convert the series to <class 'int'>
エラーは、私が行単位で個別の機能に整数列を渡す代わりにしていないことを意味します。どうすればこれを達成できますか?
をあなたはおそらく 'DF [1] = df.apply(ラムダ行をしたいです: retrieve_original_string(行[0])、軸= 1) ' – EdChum