Get the data type of column in pandas python

dtypes is the function used to get the data type of column in pandas python.It is used to get the datatype of all the column in the dataframe. Let’s see how to

  • Get the data type of all the columns in pandas python
  • Ge the data type of single column in pandas

Let’s first create the dataframe.

import pandas as pd
import numpy as np

df1 = {
    'Name':['George','Andrea','micheal','maggie','Ravi',
               'Xien','Jalpa'],
     'Gender':["M","F","M","F","M","M","F"],      
    'Score':[62.7,47.7,55.6,74.6,31.5,77.3,85.4],
    'Rounded_score':[63,48,56,75,32,77,85]
   }

df1 = pd.DataFrame(df1,columns=['Name','Gender','Score','Rounded_score'])
print(df1)

So the resultant dataframe will be

Get the data type of column in pandas python 1

 

 

Get Datatype of all the columns of dataframe in pandas:

Let’s get the data type of each column in pandas dataframe with dtypes function as shown below


''' data type of each columns'''
print(df1.dtypes)

So the result will be

Get the data type of column in pandas python 2

 

Get the datatype of a single column in pandas:

Let’s get the data type of single column in pandas dataframe by applying dtypes function on specific column as shown below


''' data type of single columns'''
print(df1['Score'].dtypes)

So the result will be

get the data type of column in pandas python 3

Get the data type of column in pandas python                                                                                                           Get the data type of column in pandas python

Author

  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.

    View all posts