Pandas DataFrame get() method with examples

Spread the love

The get() method in pandas is used to select columns from a dataframe. You can select a single column or multiple columns. When single column selected, the get method returns a series and when multiple columns are selected then it returns a dataframe.

Syntax –


key – the name of the column that you want to select.

Examples –

1 . Select a Single column –

Let’s read a dataset to work with

import pandas as pd

df = pd.read_csv(url)

Let’s say that you want to select the alcohol column from the dataframe.

# get the alcohol column

2 . Select multiple columns –

To select multiple columns, just pass the name of the columns in a list.

# get alcohol and pH columns

Rating: 1 out of 5.

Leave a Reply