I have a dataframe with a bunch of int columns plus four additional columns. I melt the dataframe. It works as expected. I then pivot-table it back. This also works fine. The only issue is that the integer columns are all converted to float64 from the combined melt\pivot_table operations. NOTE: Every single value in the affected columns is simply a zero (0) or a one (1). I end up with 1.0 or 0.0. I want to convert them back to int.
This is the code block with the issue.
exclude = ['Title', 'Votes', 'Rating', 'Revenue_Millions']
for col in re_reshaped_df.columns:
if ~col.isin(exclude):
re_reshaped_df[col] = re_reshaped_df[col].astype('int')
But I am getting this: AttributeError: 'str' object has no attribute 'isin'
The goal is to convert all columns NOT in the 'exclude' list above to int.
I was following this post: How to implement 'in' and 'not in' for Pandas dataframe
These are the columns and types:
Title object
Rating float64
Votes int64
Revenue_Millions float64
Action float64
Adventure float64
Animation float64
Biography float64
Comedy float64
Crime float64
Drama float64
Family float64
Fantasy float64
History float64
Horror float64
Music float64
Musical float64
Mystery float64
Romance float64
Sci-Fi float64
Sport float64
Thriller float64
War float64
Western float64