[Python] Error when reading a SPSS file that is in Spanish with Pandas (Python)

Discussão em 'Python' iniciado por Stack, Março 26, 2025.

  1. Stack

    Stack Membro Participativo

    Good morning!

    I am trying to work with a SPSS file (.sav) in Python.

    This is my code:

    import pandas as pd

    df=pd.read_spss('C:/Users/bonif/Documents/CSALUD01.sav')

    df.head()


    I get this error:

    df=pd.read_spss('C:/Users/bonif/Documents/CSALUD01.sav')
    File "C:\Users\bonif\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\io\spss.py", line 44, in read_spss
    df, _ = pyreadstat.read_sav(
    File "pyreadstat\pyreadstat.pyx", line 342, in pyreadstat.pyreadstat.read_sav
    File "pyreadstat\_readstat_parser.pyx", line 1034, in pyreadstat._readstat_parser.run_conversion
    File "pyreadstat\_readstat_parser.pyx", line 845, in pyreadstat._readstat_parser.run_readstat_parser
    File "pyreadstat\_readstat_parser.pyx", line 775, in pyreadstat._readstat_parser.check_exit_status
    pyreadstat._readstat_parser.ReadstatError: Unable to convert string to the requested encoding (invalid byte sequence)


    I figure out that the error may be because there are some words with the letter "ñ" or maybe some words with the following character "á". How may I solve this?

    The data base is in this google drive: https://drive.google.com/drive/folders/1P8v5NWE-GdAEJRZdmrp5KiL-DODClmfU?usp=sharing

    Thank you so much

    Continue reading...

Compartilhe esta Página