Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1064

python utf-8 encoding with pandas

$
0
0

i'm having an issue best demonstrated with this webpage https://www.basketball-reference.com/draft/NBA_2018.html which per document.charset is encoded in 'utf-8'. i use the following code

html = requests.get("https://www.basketball-reference.com/draft/NBA_2018.html", headers={"User-Agent": "XY"}).contentdf_list = pandas.read_html(html)

at which point df_list[0] correctly shows the third pick's name as Dončić in the console. okay so far so good, but what i want to do is output this table to a csv file, so i do

with open('C:/Users/Eric/br2.csv', 'a', encoding='utf-8') as f: df_list[0].to_csv(f, header=True, encoding='utf-8')

which prints the name as DonÄić. this also happens if i use the encoding 'utf-8-sig', the open doesn't work at all if i use the encoding 'latin1' or don't put an encoding on it. if i try simply printing instead of using .to_csv i still get DonÄić. if i use requests.get().text it ends up being DonÄÂić.

my question is: i've got the information extracted and properly formatted in python, how do it get it properly formatted in a file?

thanks!


Viewing all articles
Browse latest Browse all 1064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>