1

Hi I have looked but on stackoverflow and not found a solution for my problem. Any help highly appeciated.

After importing a csv I noticed that all the types of the columns are object and not float.

My goal is to convert all the columns but the YEAR column to float. I have read that you first have to strip the columns for taking blanks out and then also convert NaNs to 0 and then try to convert strings to floats. But in the code below I'm getting an error.

Table of data

My code in Jupyter notes is:

Code

And I get the following error.

Error message

How do I have to change the code.

All the columns but the YEAR column have to be set to float.

If you can help me set the column Year to datetime that would be also very nice. But my main problem is getting the data right so I can start making calculations.

Thanks

Runy

0

1 Answer 1

2

Easiest would be

df = df.astype(float)
df['YEAR'] = df['YEAR'].astype(int)

Also, your code fails because you have two columns with the same name BBPWN, so when you do df['BBPWN'], you will get a dataframe with those two columns. Then, df['BBPWN'].str will fail.

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.