As we know Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas Dataframe can be achieved in multiple ways. In this article, we will learn how to create a dataframe using two-dimensional List.
Example #1:
import pandas as pd
lst = [['Geek', 25], ['is', 30],
['for', 26], ['Geeksforgeeks', 22]]
df = pd.DataFrame(lst, columns =['Tag', 'number'])
print(df )
|
Output:
Tag number
0 Geek 25
1 is 30
2 for 26
3 Geeksforgeeks 22
Example #2:
import pandas as pd
lst = [['tom', 'reacher', 25], ['krish', 'pete', 30],
['nick', 'wilson', 26], ['juli', 'williams', 22]]
df = pd.DataFrame(lst, columns =['FName', 'LName', 'Age'],
dtype = float)
print(df)
|
Output:
FName LName Age
0 tom reacher 25
1 krish pete 30
2 nick wilson 26
3 juli williams 22
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!