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

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -