Home > Software design >  How to use lambda to change the values in dataframe?
How to use lambda to change the values in dataframe?

Time:02-02

I've tried to scale the values ​​in the dataframe by a factor of 10 to the 6th power, but the results don't show any change.

enter image description here

Energy['Energy Supply'].apply(lambda x: x*(10**6))
Energy.head()

enter image description here

CodePudding user response:

You don't need to use apply, just use compound assignment operators:

Energy['Energy Supply'] *= 1e6

CodePudding user response:

You have to add the = operator. DataFrames are not mutable like lists, therefore you have to store the value in the column: Energy['Energy Supply'] = ....

Energy['Energy Supply'] = Energy['Energy Supply'].apply(lambda x: x*(10**6))
Energy.head()
  •  Tags:  
  • Related