Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas error "***ValueError: Length mismatch: Expected axis has 0 elements, new values have..."

Tags:

python

pandas

I am getting an error when accessing data within a Pandas DataFrame df:

ipdb> df.loc[1988, 'ATTEND']
*** ValueError: Length mismatch: Expected axis has 0 elements, new values have 1481 elements

1988 and 'ATTEND' are both in df:

ipdb> 1988 in df.index
True
ipdb> 'ATTEND' in df.columns
True

I have no idea what this error is about. Any thoughts?

Thanks in advance.

Example:

ipdb> df.iloc[21875:21880, 277:280]
      FUND  ATTEND  MAATTEND
1988     3       1         4
1988     2       3         0
1988     2       2         2
1988     2       2         7
1988     2       3         2

ipdb> df.loc[1988, 'ATTEND']
*** ValueError: Length mismatch: Expected axis has 0 elements, new values have 1481 elements


GSSFilename = 'GSS Dataset/GSS7212_R2_copy.sav'
data = srw.SavReader(pathToData + GSSFilename)
df = pd.DataFrame(data.all(), index=data[:,0],    columns=ALL_VARIABLE_NAMES)
with data: 
    data = np.array(data.all()) 

UPDATE: I think this problem was caused by two different Python instances accessing the same .sav file.

like image 335
DrMisha Avatar asked Apr 04 '14 16:04

DrMisha


2 Answers

I think this problem was caused by two different Python instances accessing the same .sav file

like image 130
DrMisha Avatar answered Nov 18 '22 22:11

DrMisha


In my case, the query I was using to populate the DataFrame was returning 0 rows because the database table was empty. Once the table was populated, the error went away.

like image 21
Pawan Sharma Avatar answered Nov 18 '22 22:11

Pawan Sharma