0

I have a pandas dataframe with approx. 20 columns and I want to print out the values of only 4 columns to a csv file.

My python code is:

df(['statnr','agldate','stdragl','ff_pred']).to_csv("out.csv", sep=';')

I get this error message: TypeError: 'DataFrame' object is not callable

What am i doing wrong? Any hint is appreciated!

Thanks and kind regards, Alexander

0

2 Answers 2

1

You're using the wrong brackets.

df[['statnr','agldate','stdragl','ff_pred']].to_csv("out.csv", sep=';')

will do what you want. Round brackets, when following a character are reserved for function calls such as to_csv(). Therefore, Python is trying to call your dataframe as if it were a function, obviously producing an error

Sign up to request clarification or add additional context in comments.

Comments

0

You should,

  1. To PRINT,
print(df[['statnr','agldate','stdragl','ff_pred']].to_string())
  1. To csv file,
df[['statnr','agldate','stdragl','ff_pred']].to_csv("out.csv", sep=';')

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.