Skip to content Skip to sidebar Skip to footer

Pandas To Change The Colum Value Withoutchanging The Format

I have a Excel sheet with 10000 Rows. I have to change the value of a Colum5 based on value of Colum2 and update the excel sheet. I am able to change the values using: import nump

Solution 1:

By using .loc

df=pd.DataFrame({'Grade':['A','B','C','A','D']})
df.loc[(df.Grade=='A')&(df.index<3),'Grade']='Good'df
Out[489]: 
  Grade
0  Good
1     B
2     C
3     A
4     D

More info

(df.Grade=='A')&(df.index<3)
Out[296]: 
0True1False2False3False4False
Name: Grade, dtype: bool

Post a Comment for "Pandas To Change The Colum Value Withoutchanging The Format"