python - Correct way to select a specific column from the last row of a Dataframe -
i have dataframe stock_pick
, trying set last row of column like
stock_pick.iloc[-1]["regime"] = 0
this results in ,
/home/prowler/analysis-toolkit/anaconda2/envs/py3.6/lib/python3.6/site-packages/pandas/core/indexing.py:179: settingwithcopywarning: value trying set on copy of slice dataframe see caveats in documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy self._setitem_with_indexer(indexer, value)
what correct way pick , assign value specific column in last row?
you can use get_loc
position of column , thn posssible use dataframe.iloc
:
stock_pick.iloc[-1, stock_pick.columns.get_loc("regime")] = 0
another solution select dataframe.loc
, select index position [-1]
:
stock_pick.loc[stock_pick.index[-1], "regime"] = 0
Comments
Post a Comment