DEV Community

loading...

Answer: create list from pandas dataframe column values

Nilotpal Choudhury
Supply Chain professional with an interest in the fast growing world of data analytics
・1 min read

Pandas DataFrame columns are Pandas Series when you pull them out, which you can then call x.tolist() on to turn them into a Python list. Alternatively you cast it with list(x).

import pandas as pd

data_dict = {'one': pd.Series([1, 2, 3], index=['a', 'b', 'c']),
             'two': pd.Series([1, 2, 3, 4],

Discussion (0)