0

I am trying to add a new row to the dataframe df based on this post but I'm getting the syntax wrong. What am I missing?

df = pd.DataFrame(columns=['poll1', 'poll2','tval','pval'])
temp = pd.DataFrame([0,0,1,2], columns=['poll1', 'poll2','tval','pval'])
df.append(temp)
print(df)
1
  • Please edit your question to include the error message. Commented Mar 10, 2018 at 22:39

1 Answer 1

0
df = pd.DataFrame(columns=['poll1', 'poll2','tval','pval'], data=[[0,0,1,2]])
print(df)

or if you want to use append:

cols = ['poll1', 'poll2','tval','pval']
df = pd.DataFrame(columns=cols)
temp = pd.DataFrame(data=[[0,0,1,2]], columns = cols)
df = df.append(temp)
print(df)
Sign up to request clarification or add additional context in comments.

Comments

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.