Home > database >  change data in data frame pandas
change data in data frame pandas

Time:09-12

I have a data frame in python as below

columnA columnB
  10       15
  22       34
  44       77

i want to change columnA to read 1 less than the data it has example as below.

columnA  columnB
  9       15
 21       34
 43       77

That is 10 became 9, 22 became 21 and 44 became 43 in columnA.

CodePudding user response:

To reduce values by 1 in a pandas dataframe, here's one simple solution:

df['columnA'] = df['columnA'].apply(lambda x: x-1)

CodePudding user response:

You can directly subtract values in place:

df.columnA -= 1
  • Related