Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas read_sas "ValueError: Length of values does not match length of index"

I need some help... I got some troubles reading my sas table in python using the pandas function read_sas. I got the following error:

"ValueError: Length of values does not match length of index".

Here is the code I run:

import pandas as pd

data=pd.read_sas("my_table.sas7bdat")
data.head()

My sas table is pretty big with 505 columns and 100 000 rows.

Thanks all for your help.

like image 222
RagNar Avatar asked Oct 29 '22 08:10

RagNar


1 Answers

I had the same problem with few sas files. I solved it in 2 ways: 1. encoding

df=pd.read_csv('foo.sas7bdat.csv', encoding='iso-8859-1')

2. With sas7bdat library installed in Anaconda with:

conda install -c prometeia/label/pytho sas7bdat

In python file:

from sas7bdat import SAS7BDAT
f=SAS7BDAT('foo.sas7bdat').to_data_frame()
like image 105
Naomi Fridman Avatar answered Nov 09 '22 14:11

Naomi Fridman