Python Forum

Full Version: Convert several columns to int in dataframe
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have imported data into dataframe. Some columns have been formatted as float64 but when I try to convert to int, I get a ValueError and 'cannot convert non-finite values to integer'??
Here is my code. Can anyone advise where I have gone wrong?
df_16[['1.1 Large employers and higher managerial and administrative occupations', '1.2 Higher professional occupations', '2. Lower managerial, administrative and professional occupations', '3. Intermediate occupations', '4. Small employers and own account workers', '5. Lower supervisory and technical occupations', '6. Semi-routine occupations', '7. Routine occupations', 'L14.1 Never worked', 'L14.2 Long-term unemployed', 'L15 Full-time students', 'L17 Not classifiable for other reasons']] = df_16[['1.1 Large employers and higher managerial and administrative occupations', '1.2 Higher professional occupations', '2. Lower managerial, administrative and professional occupations', '3. Intermediate occupations', '4. Small employers and own account workers', '5. Lower supervisory and technical occupations', '6. Semi-routine occupations', '7. Routine occupations', 'L14.1 Never worked', 'L14.2 Long-term unemployed', 'L15 Full-time students', 'L17 Not classifiable for other reasons']].round(0).astype(int)
please format your code You can't show it that way ;

probably missing values in your data, chek that: df.isnull().sum()
Yes that was the issue. Thanks!