Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

็How to multiply specific range of data in dataframe python

as I already mentioned in the title.

For example, I have a dataframe in python like this :

dataframe = pd.DataFrame({‘Energy Consumption’: [20, 21, 19, 18, 25, 40, 18]})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I want to multiply a number such as 0.3 on row index 3 to the end. How can I do that by the shortest operation time.

Thanks in advance.

>Solution :

You can do loc(assume the index is from 0 to n-1 , if not df.reset_index(drop=True, inplace=True) before below)

dataframe.loc[2:,'Energy Consumption'] *= 0.3
dataframe
   Energy Consumption
0                20.0
1                21.0
2                 5.7
3                 5.4
4                 7.5
5                12.0
6                 5.4
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading