In Python, I'm writing my Pandas Dataframe to a csv file and want to change the decimal delimiter to a comma (,
). Like this:
results.to_csv('D:/Data/Kaeashi/BigData/ProcessMining/Voorbeelden/Voorbeeld/CaseEventsCel.csv', sep=';', decimal=',')
But the decimal delimiter in the csv file still is a .
Why? What do I do wrong?
Pandas DataFrame to_csv() function converts DataFrame into CSV data. We can pass a file object to write the CSV data into a file. Otherwise, the CSV data is returned in the string format.
Does pandas To_csv overwrite? If the file already exists, it will be overwritten. If no path is given, then the Frame will be serialized into a string, and that string will be returned.
round() function is used to round a DataFrame to a variable number of decimal places. This function provides the flexibility to round different columns by different places.
If the decimal
parameter doesn't work, maybe it's because the type of the column is object
. (check the dtype
value in the last line when you do df[column_name]
)
That can happen if some rows have values that couldn't be parsed as numbers.
You can force the column to change type: Change data type of columns in Pandas. But that can make you lose non numerical data in that column.
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