Python Practice › Pandas Programs › Program 57
Column values as a list
Write a pandas program to get the values of a column as a list.
Output
['Alex', 'John', 'Peter']
Approach
df["col"].tolist().
Solution
import pandas as pddf = pd.DataFrame({"name": ["Alex", "John", "Peter"], "salary": [50000, 65000, 63000]})print(df["name"].tolist())Output
['Alex', 'John', 'Peter']
Learn the concept
New to this topic? Read the lesson, then come back.