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.
I think this problem was caused by two different Python instances accessing the same .sav file
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With