Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
How to Check the Data Type in Pandas DataFrame?
Next article icon

How to Check the Data Type in Pandas DataFrame?

Last Updated : 08 Sep, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Pandas DataFrame is a Two-dimensional data structure of mutable size and heterogeneous tabular data. There are different Built-in data types available in Python.  Two methods used to check the datatypes are pandas.DataFrame.dtypes and pandas.DataFrame.select_dtypes.

Creating a Dataframe to Check DataType in Pandas DataFrame

Consider a dataset of a shopping store having data about Customer Serial Number, Customer Name, Product ID of the purchased item, Product Cost, and Date of Purchase.

Python3
#importing pandas as pd import pandas as pd  # Create the dataframe  df = pd.DataFrame({ 'Cust_No': [1,2,3], 'Cust_Name': ['Alex', 'Bob', 'Sophie'], 'Product_id': [12458,48484,11311], 'Product_cost': [65.25, 25.95, 100.99], 'Purchase_Date': [pd.Timestamp('20180917'),                   pd.Timestamp('20190910'),                   pd.Timestamp('20200610')] })  # Print the dataframe  df 

Output: 

 

Check the Data Type in Pandas using pandas.DataFrame.dtypes 

For users to check the DataType of a particular Dataset or particular column from the dataset can use this method. This method returns a list of data types for each column or also returns just a data type of a particular column

Example 1:

Python3
# Print a list datatypes of all columns  df.dtypes 

 Output:

 

Example 2:

Python3
# print datatype of particular column df.Cust_No.dtypes 

Output: 

dtype('int64')

Example 3:

Python3
# Checking the Data Type of a Particular Column df['Product_cost'].dtypes 

Output: 

dtype('float64')

Check the Data Type in Pandas using pandas.DataFrame.select_dtypes 

Unlike checking Data Type user can alternatively perform a check to get the data for a particular Datatype if it is existing otherwise get an empty dataset in return. This method returns a subset of the DataFrame’s columns based on the column dtypes.

Example 1:

Python3
# Returns Two column of int64  df.select_dtypes(include = 'int64')  

Output: 

 

Example 2: 

Python3
# Returns columns excluding int64  df.select_dtypes(exclude = 'int64')  

Output : 

 

Example 3 : 

Python3
# Print an empty list as there is # no column of bool type df.select_dtypes(include = "bool")  

Output : 

 

Next Article
How to Check the Data Type in Pandas DataFrame?

A

abhishekkharmale
Improve
Article Tags :
  • Python
  • Python-pandas
  • Python pandas-dataFrame
Practice Tags :
  • python

Similar Reads

    How to Convert String to Float in Pandas DataFrame
    Converting Strings to Float in Pandas DataFrame is a very crucial step for data analysis. Converting string to float values can help you perform various arithmetic operations and plot graphs. In this article, we'll look at different ways to convert a string to a float in DataFrame. Creating Sample D
    4 min read
    How to Change Column Type in PySpark Dataframe ?
    In this article, we are going to see how to change the column type of pyspark dataframe. Creating dataframe for demonstration: Python # Create a spark session from pyspark.sql import SparkSession spark = SparkSession.builder.appName('SparkExamples').getOrCreate() # Create a spark dataframe columns =
    4 min read
    How to Convert String to Integer in Pandas DataFrame?
    Let's see methods to convert string to an integer in Pandas DataFrame: Method 1: Use of Series.astype() method. Syntax: Series.astype(dtype, copy=True, errors=’raise’) Parameters: This method will take following parameters: dtype: Data type to convert the series into. (for example str, float, int).c
    3 min read
    How to Convert Floats to Strings in Pandas DataFrame?
    In this post, we'll see different ways to Convert Floats to Strings in Pandas Dataframe? Pandas Dataframe provides the freedom to change the data type of column values. We can change them from Integers to Float type, Integer to String, String to Integer, Float to String, etc. There are three methods
    4 min read
    Change Data Type for one or more columns in Pandas Dataframe
    When working with data in Pandas working with right data types for your columns is important for accurate analysis and efficient processing. Pandas offers several simple ways to change or convert the data types of columns in a DataFrame. In this article, we'll look at different methods to help you e
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences