Python1
Import pandas library
import pandas as pd
data [["Tata', 'Nexon, 2017], ["MG", "Astor, 2021], ["XIA', 'Seltos, 20191, (Hyundai
reta", 201511
Create a list of lists
Create the pandas DataFrame df = pd.DataFrame(data, columns['ccepany, 'model', 'year'11
print the dataframe, dt
Python 2:
import pandas as pd
import numpy as np
Pass a 20 numpy array each row is the corresponding row in the dataframe data= np.array([('Tata', 'Nexon', 2017). I'KIA', 'Seltoa', 20191,
IMG', 'Astor, 20211,
[Hyundai, Creta', 2015111
1 pass column names in the columns parameter of the constructor df = pd.DataFrame(data, columns = ['company', 'model', 'year']]
df
Python 3
import pandas as pd
#Create the dictionary
data('company': ['Tata', 'MG', 'KIA', 'Hyundai'], 'model': ('Nexon', 'Astor', 'Seltos', 'Creta'],
'year' [2017, 2021,2019,2015]
}
#Create the dataframe df pd.DataFrame.from_dict (data) #Print the dataframe df
Python 4
import pandas as pd
#Each dictionary is a record in the dataframe. #Dictionary Keys become Column names in the dataframe. Dictionary values become the
values of columns
data = [{'company': 'Tata', 'model': 'Nexon', 'year': 2017),
{'company': 'MG', 'model' : 'Astor', 'year': 2021),
('company': 'KIA', 'model' : 'Seltos', 'year': 2019),
('company': 'Hyundai', 'model': 'Creta', 'year': 2015)]
df = pd.DataFrame (data)
df
0 Comments