divide a column value in pandas dataframe 1

divide a column value in pandas dataframe

df = pd.DataFrame({'A':[61.75, 10.25], 'B':[0.62, 0.45]})
print (df)
       A     B
0  61.75  0.62
1  10.25  0.45

df['A'] = df['A'].div(100).round(2)
#same as
#df['A'] = (df['A'] / 100).round(2)
print (df)
      A     B
0  0.62  0.62
1  0.10  0.45

Here is what the above code is Doing:
1. Create a dataframe with two columns, A and B.
2. Print the dataframe.
3. Divide the values in column A by 100 and round to 2 decimal places.
4. Print the dataframe again.

Similar Posts