Answers for "astype dataframe"

0

pandas astype datetime

# converting the string to datetime format
df['Dates'] = pd.to_datetime(df['Dates'], format='%y%m%d')
 
# printing dataframe
print(df)
print(df.dtypes)
Posted by: Guest on April-08-2021
2

convert pandas column type

# convert all columns of DataFrame
df = df.apply(pd.to_numeric) # convert all columns of DataFrame

# convert just columns "a" and "b"
df[["a", "b"]] = df[["a", "b"]].apply(pd.to_numeric)
Posted by: Guest on April-06-2021

Python Answers by Framework

Browse Popular Code Answers by Language