SNIPPET
2 Upvotes

Converting Data Types

Python
Data Preprocessing

Shows how to convert dataframe column to different data types. We see how to convert to string, integer and float.

#GENERAL SYNTAX
df[column_name] = df[column_name].astype(data type)

#CONVERTING TO STRING
df[column_name] = df[column_name].astype(str)

#CONVERTING TO INTEGER
df[column_name] = df[column_name].astype(int)

#CONVERTING TO FLOAT
df[column_name] = df[column_name].astype(float)

By analyseup - Last Updated Dec. 12, 2020, 3:55 p.m.

COMMENTS
RELATED SNIPPETS
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3
SparkSession instantiate
Python
Data Preprocessing

2
Data Minification
Python
Data Preprocessing

Cleaning

2
Search Snippets by Tag: