1

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

3
  • Please note that in general, it is better to post example data / code as text instead of image - it's also more likely that you'll get a helpful answer then. Commented Feb 2, 2022 at 10:53
  • 2
    Regarding the Q, apply doesn't work in-place, you need to re-assign the returned series; Energy['Energy Supply'] = Energy['Energy Supply'].apply(lambda x: x*(10**6)). Commented Feb 2, 2022 at 10:54
  • assign the value to the column Commented Feb 2, 2022 at 10:54

2 Answers 2

3

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()
Sign up to request clarification or add additional context in comments.

Comments

3

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

Energy['Energy Supply'] *= 1e6

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.