1
df = pd.DataFrame(index=pd.date_range('2017-01-01', '2017-01-10', freq='D'), columns=['test'])

vals = np.array([1.0, 2.0])

df['test'] = vals

I get this error: ValueError: Length of values does not match length of index

Any way I can fix it? This error is arising because lenght of vals is less than length of df. I want to insert numpy NaNs for the places where I have no values.

0

1 Answer 1

3

You can assign to just the first rows like this:

df['test'][:len(vals)] = vals
Sign up to request clarification or add additional context in comments.

1 Comment

sweet! so obvious now that you have posted the soln

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.