Tutorials References Exercises Videos Menu
Create Website Get Certified Upgrade

Pandas DataFrame get() Method

❮ DataFrame Reference


Example

Extract the "firstname" column from the DataFrame:

import pandas as pd

data = {
  "firstname": ["Sally", "Mary", "John"],
  "age": [50, 40, 30],
  "qualified": [True, False, False]
}

df = pd.DataFrame(data)
print(df.get("firstname"))
Try it Yourself »

Definition and Usage

The get() method returns the specified column(s) from the DataFrame.

If you specify only one column, the return value is a Pandas Series object.

To specify more than one column, specify the columns inside an array. The result will be a new DataFrame object.


Syntax

dataframe.get(key)

Parameters

Parameter Description
key  Optional. A String or object representing the column(s) you want to return


Return Value

If only one column is returned: a Pandas Series object.

If more than one column are returned: a Pandas DataFrame object.


❮ DataFrame Reference