Create pandas DataFrame from List Object in Python (Example Code)
This tutorial explains how to convert a list to a pandas DataFrame in Python programming.
Creating Example Data
lst = ['a', 'b', 'a', 'a', 'c', 'b'] # Constructing an example list print(lst) # ['a', 'b', 'a', 'a', 'c', 'b'] |
lst = ['a', 'b', 'a', 'a', 'c', 'b'] # Constructing an example list print(lst) # ['a', 'b', 'a', 'a', 'c', 'b']
Example: Create pandas Dataframe with List as Column
import pandas as pd # Load pandas library |
import pandas as pd # Load pandas library
df = pd.DataFrame({'lst': lst}) # Convert list to pandas DataFrame print(df) # lst # 0 a # 1 b # 2 a # 3 a # 4 c # 5 b |
df = pd.DataFrame({'lst': lst}) # Convert list to pandas DataFrame print(df) # lst # 0 a # 1 b # 2 a # 3 a # 4 c # 5 b
Further Resources
Here, you may find some additional resources on topics such as variables, lists, and data conversion: