
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python – Get the datatypes of columns
To get the datatypes of columns, use the info() method. Let us first import the required library −
import pandas as pd
Create a DataFrame with 2 columns having different datatypes −
dataFrame = pd.DataFrame( { "Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],"Roll Number": [ 5, 10, 3, 8, 2, 9, 6] } )
Get the complete information about datatypes −
dataFrame.info()
Example
Following is the complete code −
import pandas as pd # Create DataFrame dataFrame = pd.DataFrame( { "Student": ['Jack', 'Robin', 'Ted', 'Marc', 'Scarlett', 'Kat', 'John'],"Roll Number": [ 5, 10, 3, 8, 2, 9, 6] } ) print"DataFrame ...\n",dataFrame print"\nInfo and the datatypes of the columns in the dataframe:\n" # get the datatypes info print(dataFrame.info())
Output
This will produce the following output −
DataFrame ... Roll Number Student 0 5 Jack 1 10 Robin 2 3 Ted 3 8 Marc 4 2 Scarlett 5 9 Kat 6 6 John Info and the datatypes of the columns in the dataframe: <class 'pandas.core.frame.DataFrame'> RangeIndex: 7 entries, 0 to 6 Data columns (total 2 columns): Roll Number 7 non-null int64 Student 7 non-null object dtypes: int64(1), object(1) memory usage: 184.0+ bytes None
- Related Articles
- Python - Select columns with specific datatypes
- Python Container Datatypes
- How to select multiple DataFrame columns using regexp and datatypes
- Write a program to get the list of all the supported datatypes in JDBC?
- Python Pandas – Get the datatype and DataFrame columns information
- Python Pandas - Form the Union of two Index objects with different datatypes
- Display the limits of DataTypes in Java
- Overflow of DataTypes in Java
- Underflow of DataTypes in Java
- Python – Get the Columns Shared by Two Pandas DataFrames using Numpy
- What is the C# Equivalent of SQL Server DataTypes?
- How to get the datatype of MySQL table columns?
- Get the number of columns in a MySQL table?
- How to get the mean of columns that contains numeric values of a dataframe in Pandas Python?
- Get the sum of columns for duplicate records in MySQL

Advertisements