Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Python - Typecasting Pandas into set
To typecast pandas into Set, use the set(). At first, let us create a DataFrame −
dataFrame = pd.DataFrame(
{
"EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', 'Ted', 'Scarlett'],
"Zone": ['North', 'South', 'South', 'East', 'West', 'East', 'North']
}
)
Typecast pandas to set and then take set union −
set(dataFrame.EmpName) | set(dataFrame.Zone)
Example
Following is the complete code −
import pandas as pd
# Create DataFrame
dataFrame = pd.DataFrame(
{
"EmpName": ['John', 'Ted', 'Jacob', 'Scarlett', 'Ami', 'Ted', 'Scarlett'],
"Zone": ['North', 'South', 'South', 'East', 'West', 'East', 'North']
}
)
print"DataFrame ...\n",dataFrame
# Pandas into Set
print"\nTypecast Pandas into Set...\n",set(dataFrame.EmpName) | set(dataFrame.Zone)
Output
This will produce the following output −
DataFrame ... EmpName Zone 0 John North 1 Ted South 2 Jacob South 3 Scarlett East 4 Ami West 5 Ted East 6 Scarlett North Typecast Pandas into Set... set(['Ami', 'East', 'North', 'West', 'Ted', 'South', 'Jacob', 'John', 'Scarlett'])
Advertisements
