Pandas DataFrame: update all values in all columns, based on condition
Question:
Check all column’s values. If the value is greater than 100,000:
-> Subtract 4294967295 and then add 1 to it.
I did it, but for one column like this:
df.loc[df['12:00AM'] > 100000, '12:00AM'] = (4294967295 - df.loc[df['12:00AM'] > 100000, '12:00AM']) +1
I want to apply this code for all columns.
Answers:
I did it like this: where : A-B = -B+A
df[df> 100000] = -1*df[df> 100000] + 4294967295+1
Check all column’s values. If the value is greater than 100,000:
-> Subtract 4294967295 and then add 1 to it.
I did it, but for one column like this:
df.loc[df['12:00AM'] > 100000, '12:00AM'] = (4294967295 - df.loc[df['12:00AM'] > 100000, '12:00AM']) +1
I want to apply this code for all columns.
I did it like this: where : A-B = -B+A
df[df> 100000] = -1*df[df> 100000] + 4294967295+1