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

Change the specified cell in the data frame in Python

I have a data frame like below:

0       INT_ID  F1_ID  chr  start   T1    T2
1  F143-F44837    143    1   5000   True  True
2    F144-F153    144    1  15000   True  True
3    F152-F153    152    1  20000   True  True
4    F152-F175    152    2  25000   True  True
5    F152-F175    152    3  40000   True  True

and I want to change a particular cell.
for example :

if F1_ID==144 and start==15000 then T1 should be False.

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

how can I change a cell in data frame pandas in python?

>Solution :

Use loc and your conditions. It is important to use loc to avoid SettingWithCopyWarning.

df.loc[df['F1_ID'].eq(144) & df['start'].eq( 15000), 'T1'] = False

output:

   0       INT_ID  F1_ID  chr  start     T1    T2
0  1  F143-F44837    143    1   5000   True  True
1  2    F144-F153    144    1  15000  False  True
2  3    F152-F153    152    1  20000   True  True
3  4    F152-F175    152    2  25000   True  True
4  5    F152-F175    152    3  40000   True  True
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