Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas columns to int64 with nan

# single column
df['column_name'].apply(pd.to_numeric).astype('Int64')

# range of cols
df.loc[:, 'col_n':'col_m'] = df.loc[:, 'col_n':'col_m'].apply(pd.to_numeric).astype('Int64')

'''
From Pandas v0.24, introduces Nullable Integer Data Types 
which allows integers to coexist with NaNs.
'''
 
PREVIOUS NEXT
Tagged: #pandas #columns #nan
ADD COMMENT
Topic
Name
2+7 =