I was trying to rewrite a CSV file using pandas module in python. I tried to multiply the first column (excluding the title) by 60 as below,
f=001.csv
Urbs_Data=pd.read_csv(f,header=None)
Urbs_Data=Urbs_Data.replace("Time_hrs","Time_min")
Urbs_Data.loc[1:,0]=Urbs_Data.loc[1:,0].astype(float)
Urbs_Data.loc[1:,0]*=60
It gives me some funny number for the first column, as
124.98000000000002,462.67
130.01999999999998,460.34
135.0,454.36
139.98000000000002,443.29
Is there any way to limit the number of decimal places for those numbers (to 2)? I tried to use the normal round function, it does not work for me.
The DataFrame round method should work...
import numpy as np
import pandas as pd
some_numbers = np.random.ranf(5)
df = pd.DataFrame({'random_numbers':some_numbers})
rounded_df = df.round(decimals=2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With