Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame pipe() Method

❮ DataFrame Reference


Example

Apply a function to the DataFrame that will overwrite the "age" column:

import pandas as pd

def change_age(x):
  x["age"]=[10, 20, 30]
  return x

data = {
  "name": ["Sally", "Mary", "John"],
  "age": [50, 40, 30]
}

df = pd.DataFrame(data)
df.pipe(change_age)
print(df)
Try it Yourself »

Definition and Usage

The pipe() method allows you to apply one or more functions to the DataFrame object.


Syntax

dataframe.pipe(func, args, kwargs)

Parameters

Parameter Description
func Required. A function to apply to the DataFrame.
args Optional, An iterable object with positional arguments that can be used in the function
kwargs Optional. A dictionary with keyword arguments that can be used in the function

Return Value

A DataFrame object.

This function makes changes to the original DataFrame object.


❮ DataFrame Reference