We can create a panda data frame from a list using the DataFrame() function.
Creating a Dataframe using Lists
Example 1:
import pandas as pd
data = [['USA', 'New York', 8623000],
['USA', 'Los Angeles', 3990456],
['USA', 'Chicago', 2705994],
['China', 'Shanghai', 24183300],
['China', 'Beijing', 21707000],
['India', 'Mumbai', 18414230]]
# DataFrame from the list
df = pd.DataFrame(data, columns=['Country', 'City', 'Population'])
print(df)
Output:
Country City Population
0 USA New York 8623000
1 USA Los Angeles 3990456
2 USA Chicago 2705994
3 China Shanghai 24183300
4 China Beijing 21707000
5 India Mumbai 18414230
Example 2:
import pandas as pd
data = [['US Treasury', 'USA', 1.8],
['German Bund', 'Germany', 0.5],
['UK Gilt', 'UK', 1.2],
['Japanese Government Bond', 'Japan', 0.1],
['Australian Government Bond', 'Australia', 2.3]]
df = pd.DataFrame(data, columns=['Bond', 'Country', 'Rate'])
print(df)
Output:

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!