- 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 - Create a Pipeline in Pandas
To create a pipeline in Pandas, we need to use the pipe() method. At first, import the required pandas library with an alias −
import pandas as pd
Now, create a DataFrame −
dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )
Create a pipeline and call the upperFunc() custom function to convert column names to uppercase −
pipeline = dataFrame.pipe(upperFunc)
Following is the upperFun() to convert column names to uppercase −
def upperFunc(dataframe): # Converting to upppercase dataframe.columns = dataframe.columns.str.upper() return dataframe
Example
Following is the complete code −
import pandas as pd # function to convert column names to uppercase def upperFunc(dataframe): # Converting to upppercase dataframe.columns = dataframe.columns.str.upper() return dataframe # Create DataFrame dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } ) print"DataFrame ...\n",dataFrame # creating pipeline using pipe() pipeline = dataFrame.pipe(upperFunc) # calling pipeline print"\nDisplaying column names in uppercase...\n",pipeline
Output
This will produce the following output
DataFrame ... Car Units 0 BMW 100 1 Lexus 150 2 Audi 110 3 Mustang 80 4 Bentley 110 5 Jaguar 90 Displaying column names in uppercase... CAR UNITS 0 BMW 100 1 Lexus 150 2 Audi 110 3 Mustang 80 4 Bentley 110 5 Jaguar 90
Advertisements