0
で一定値とコードの上正常に動作し、私は別の列の値に基づいて、パンダのデータフレームの列の値を設定しようとしています列
df2.loc[df2['col1',len] == val, 'col2'] = df1['col2']
をパンダのデータフレームの最初の数行を選択し、しかし、今の問題は、私は最初の数行の値を設定したいということである以下のようなもの:
len1 = len(df1.index)
df2.loc[df2['col1',len1] == val, 'col2'] = df1['col2']
しかし、私は次のようなエラーになっています:
を10Traceback (most recent call last): File "...\lib\site-packages\pandas\indexes\base.py", line 1945, in get_loc return self._engine.get_loc(key) File "pandas\index.pyx", line 137, in pandas.index.IndexEngine.get_loc (pandas\index.c:4154) File "pandas\index.pyx", line 159, in pandas.index.IndexEngine.get_loc (pandas\index.c:4018) File "pandas\hashtable.pyx", line 675, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12368)
ご協力いただければ幸いです。これに
しかし、df2内のcol2の値は変更されません。 – Annie
変更されました。今すぐ動作します –
http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy – Annie