Home > Blockchain >  set slice in pandas date-index dataframe with number position for row and label for column
set slice in pandas date-index dataframe with number position for row and label for column

Time:08-26

Consider the dataframe

                    name1   name2  randomSetOfColumns name3 randomSetOfColumns
Date        
...                                                 
2001-02-22 15:15:00 200     300     ...                1      ...
2001-02-22 15:20:00 201     301     ...                2      ...
...

I want to change the values in rows between 20 and 30 in column "name3". With ix being deprecated, I don't know how to mix numerical row index and label column index.

CodePudding user response:

See Combining positional and label-based indexing:

df.loc[df.index[20:31], 'name3']

or

df.iloc[20:31, df.columns.get_loc('name3')]

to select rows 20 through 30 (including 30).

  • Related