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 import pandas as pd # List1 lst = [[ 'Geek' , 25 ], [ 'is' , 30 ], [ 'for' , 26 ], [ 'GeeksforLazyroar' , 22 ]] # creating df object with columns specified df = pd.DataFrame(lst, columns = [ 'Tag' , 'number' ]) print (df ) |
Output:
Tag number 0 Geek 25 1 is 30 2 for 26 3 GeeksforLazyroar 22
Example #2:
import pandas as pd # List1 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