Skip to content
Advertisement

Selecting/Manuplating cells based on their location in the dataframe

I have a dataframe as below

JavaScript

I want to multiply every 3rd column after the 2 column in the last 2 rows by 5 to get the ouput as below.

How to acomplish this?

JavaScript

I am able to select the cells i need with df.iloc[-2:,1::3] which results in the df as below but I am not able to proceed further.

JavaScript

I know that I can select the same cells with loc instead of iloc, then the calcualtion is straign forward, but i am not able to figure it out. The column names & cell values CANNOT Be used since these change (the df here is just a dummy data)

Advertisement

Answer

You can assign back to same selection of rows/ columns like:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement