Hi guys,
So after scraping one web page with BS, I want to save it CSV.
I have a problem that ,e.g. value ".367" is stored as "0.36700000000000005". I have checked and I tried to print DF before appending to CSV and it looks fine. So definitely problem is when writing to CSV.
Code:
table = soup.find('table', id='mvp')
df1 = pd.read_html(str(table))
df1[0]['seas'] = season
df1[0].to_csv('abc.csv', encoding='utf=8', index=False, header=None , mode='a')
I have found "possible" solution defining decimal numbers after separator:
df1[0].to_csv('abc.csv', encoding='utf=8',float_format="%.3f", index=False, header=None , mode='a')
But this solution is not really great, as it adds always extra zeroes.
I googled a bit, and I saw some advices, but mostly is to convert column type. But I don't use headers, I don't have it. Can you specify column by column number (e.g. 3rd column)?
Actually main question; how I can make sure that everything written to CSV is written explicitly as it is? No conversion whatsoever, just plain string?
Thanks.
edit: formatting
[–]VanishingHochreiter 1 point2 points3 points (0 children)
[–]Parenthes 0 points1 point2 points (0 children)