0
Pandas dataframe.round
in: df = pd.read_csv("tsla.csv", nrows=500) df.round(-3) df.head() out: Date High Low Open Close Volume Adj Close 0 2010-06-29 25.00 17.540001 19.000000 23.889999 18766300 23.889999 1 2010-06-30 30.42 23.299999 25.790001 23.830000 17187100 23.830000 2 2010-07-01 25.92 20.270000 25.000000 21.959999 8218800 21.959999 3 2010-07-02 23.10 18.709999 23.000000 19.200001 5139800 19.200001 4 2010-07-06 20.00 15.830000 20.000000 16.110001 6866900 16.110001 I don`t understand why I could not round them. can anyone help me to figure it out?
2 Answers
+ 2
How many digits do you want to keep after the decimal point? Minus 3 looks strange to me.
Also try to reassign the rounded values to the dataframe:
df = df.round(3)
If still not working as expected then it might be a datatype issue and you may need to cast the rounded values as decimal instead of float.
0
thanks for your answer.
I am sorry that -3 should be 3.
I removed df.head(), and it rounded dataframe.
But my next question is going to be whether I cannot get head or tail data that is rounded...