Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I am trying to dowload a csv in python but all i get is weird symbols

I am trying to download this csv in this link when i download with the browser it’s ok but the code I can’t
https://www.policyuncertainty.com/media/Global_Policy_Uncertainty_Data.csv
I have tried using pandas with utf-8 and latin-1:

If I do it without encoding I get this error : ‘utf-8’ codec can’t decode byte 0xf5 in position 5: invalid start byte

data = pd.read_csv('https://www.policyuncertainty.com/media/Global_Policy_Uncertainty_Data.csv',encoding='iso-8859-1')

I also tried with this code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

url = "https://www.policyuncertainty.com/media/Global_Policy_Uncertainty_Data.csv"
response = requests.get(url)        

with open(ruta+"/Global_Policy_Uncertainty_Data.csv", "w") as f:
    writer = csv.writer(f)
    for line in response.iter_lines():
        print(line)
        writer.writerow(line.decode("ISO-8859-1").split("",""),escapechar="/")

but I always get this weird symbols in the file
probably because I don’t have the right encoding, but when I use postman it gives me a normal data

>Solution :

Changing https to http in the url solved the issue for me:

data = pd.read_csv('http://www.policyuncertainty.com/media/Global_Policy_Uncertainty_Data.csv')

The issue could be from due to an invalid URL scheme. From pandas read_csv documentation: ‘Valid URL schemes include http, ftp, s3, gs, and file.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading