- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Return the dtype object of the underlying data
To return the dtype object of the underlying data, use the index.dtype property in Pandas.
At first, import the required libraries −
import pandas as pd
Creating the index −
index = pd.Index(['Car','Bike', 'Shop','Car','Airplace', 'Truck'])
Display the index −
print("Pandas Index...\n",index)
Return the dtype of the data −
print("\nThe dtype object...\n",index.dtype)
Example
Following is the code −
import pandas as pd # Creating the index index = pd.Index(['Car','Bike', 'Shop','Car','Airplace', 'Truck']) # Display the index print("Pandas Index...\n",index) # Return an array representing the data in the Index print("\nArray...\n",index.values) # Return the dtype of the data print("\nThe dtype object...\n",index.dtype) # Return a tuple of the shape of the underlying data print("\nA tuple of the shape of underlying data...\n",index.shape)
Output
This will produce the following code −
Pandas Index... Index(['Car', 'Bike', 'Shop', 'Car', 'Airplace', 'Truck'], dtype='object') Array... ['Car' 'Bike' 'Shop' 'Car' 'Airplace' 'Truck'] The dtype object... object A tuple of the shape of underlying data... (6,)
Advertisements