Я пытаюсь сделать какое-то соединение между двумя кадрами данных, и я использовал iterrows поверх двух данных, чтобы получить индекс и значение столбца X, чтобы я мог присвоить значение столбца Y левой таблице!
Я использовал следующее:
for row_index,row in df.iterrows():
for idx, r in pp.iterrows():
if str(df.iloc[row_index]['nom_ens']) == str(pp.iloc[idx]['NOM_ENSEMBLE']) or (str(df.iloc[row_index]['nom_ens']) in str(pp.iloc[idx]['NOM_ENSEMBLE'])):
df.iloc[row_index]["CODE_ENSEMBLE_IMMO"]=pp.iloc[idx]['CODE_ENSEMBLE_IMMO']
И я получаю следующую ошибку:
/usr/local/lib/python3.6/dist-packages/ipykernel_launcher.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame
See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
after removing the cwd from sys.path.
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-161-0895ce943ee3> in <module>()
1 for idx, r in pp.iterrows():
2 for row_index,row in df.iterrows():
----> 3 if str(df.iloc[row_index]['nom_ens']) == str(pp.iloc[idx]['NOM_ENSEMBLE']) or (str(df.iloc[row_index]['nom_ens']) in str(pp.iloc[idx]['NOM_ENSEMBLE'])):
4 df.iloc[row_index]["CODE_ENSEMBLE_IMMO"]=pp.iloc[idx]['CODE_ENSEMBLE_IMMO']
5
/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in __getitem__(self, key)
1371
1372 maybe_callable = com._apply_if_callable(key, self.obj)
-> 1373 return self._getitem_axis(maybe_callable, axis=axis)
1374
1375 def _is_scalar_access(self, key):
/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1828
1829 # validate the location
-> 1830 self._is_valid_integer(key, axis)
1831
1832 return self._get_loc(key, axis=axis)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py in _is_valid_integer(self, key, axis)
1711 l = len(ax)
1712 if key >= l or key < -l:
-> 1713 raise IndexError("single positional indexer is out-of-bounds")
1714 return True
1715
IndexError: single positional indexer is out-of-bounds