Trying to get my column to be formatted as INT as the 1.0 2.0 3.0 is causing issues with how I am using the data. The first thing I tried was df['Severity'] = pd.to_numeric(df['Severity'], errors='coerce')
. While this looked like it worked initially, it reverted back to appearing as float when I wrote to csv. Next I tried using df['Severity'] = df['Severity'].astype(int)
followed by another failed attempt using df['Severity'] = df['Severity'].astype(int, errors='coerce')
because it seemed a logical solution to me.
I did some digging into pandas' docs and found this regarding how pandas handles NAs:
Typeclass Promotion dtype for storing NAs
floating no change
object no change
integer cast to float64
boolean cast to object
What I find strange though, is that when I run df.info(), I get Severity 452646 non-null object
Sample Data:
Age,Severity
1,1
2,2
3,3
4,NaN
5,4
6,4
7,5
8,7
9,6
10,5
Any help would be greatly appreciated :)