Indexing and selecting data — pandas 2.3.2 documentation

Import the library:

import pandas as pd

Read a dataset:

data = {'A': [30, 45], 'B': [45, 55], 'C': [45, 60], 'D': [75, 80]}
# Read the dataset
df = pd.DataFrame(data)
# Display the dataset
print(df)

Output:

    A   B   C   D
0  30  45  45  75
1  45  55  60  80

Some basic ways to retrieve the values in the dataset

# Display the elements in column A and B
print(df['A'])
print(df['B'])

Output:

0    30
1    45
Name: A, dtype: int64
0    45
1    55
Name: B, dtype: int64

The following line is invalid

print(df['A', 'B'])

Correct version:

print(df[['A', 'B']])