Search
 
SCRIPT & CODE EXAMPLE
 

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.
'''
Comment

pandas nan to None

df = df.astype("object").where(pd.notnull(df), None)
Comment

pandas nan to none

df1 = df.where(pd.notnull(df), None)
Comment

Convert nan into None in df

df. replace(np. nan,'',regex=True) 
Comment

PREVIOUS NEXT
Code Example
Python :: python sort a list of tuples 
Python :: parse datetime python 
Python :: check if special character in string python 
Python :: clear screen python 
Python :: pandas select all columns except one 
Python :: convert pandas series from str to int 
Python :: How to config your flask for gmail 
Python :: Write a line to a text file using the write() function 
Python :: create boto3 s3 client with credentials 
Python :: python3 install google 
Python :: pandas how to get last index 
Python :: python count number of zeros in a column 
Python :: python write to json with indent 
Python :: alias python in macbook 
Python :: how to save python list to file 
Python :: Python Current time using datetime object 
Python :: matplotlib plot title font size 
Python :: verificar se arquivo existe python 
Python :: save list pickle 
Python :: how to read tsv file python 
Python :: image in cv2 
Python :: cv2 draw box 
Python :: draw a line pygame 
Python :: how to lowercase list in python 
Python :: stripping /n in a readlines for a pytgon file 
Python :: pandas select by column value 
Python :: print type of exception python 
Python :: python split path at level 
Python :: how to make a blank window open up in python 
Python :: python install required packages 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =