0

I have a df pretty much big...around 360 rows and 4000 cols. I have the needs to find out the way to iterate over rows and columns to check if the value of each cell is bigger / smaller of +/- 1. In this case I would like to replace the cell with 0 or Nan.

Table

I tried with:

for idx,row in switz_fund_ret.iloc[1:, 1:3631].iterrows(): 
    for col in row: 
        if col > 1: 
            switz_fund_ret.drop(idx,inplace=True) 

but I received:

KeyError: '[datetime.datetime(2006, 12, 4, 0, 0)] not found in axis'
cs95
  • 379,657
  • 97
  • 704
  • 746
  • Can you provide a **minimal** example of the DataFrame that will illustrate the problem? - [mcve] – wwii Feb 17 '20 at 19:21
  • `.drop` removes an entire row/column - is that what you want? It may have already removed it on a previous iteration causing the KeyError. - https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.drop.html – wwii Feb 17 '20 at 19:29
  • Does this answer your question? [Update row values where certain condition is met in pandas](https://stackoverflow.com/questions/36909977/update-row-values-where-certain-condition-is-met-in-pandas) , or maybe this one [Replace value for a selected cell in pandas DataFrame without using index](https://stackoverflow.com/questions/17729853/replace-value-for-a-selected-cell-in-pandas-dataframe-without-using-index) – wwii Feb 17 '20 at 20:05

0 Answers0