I am new to Python world. How can we create a dataframe with an existing dictionary where the values are arrays.
The data looks like :
data={'first':['A','B','C','D','E','F'],'second':[10,20,30,40,50,60],'third':[1.1,2.5,3.4,5.4,6.7,8.9]}
After the. creation of the dataframe, it would look like this :
first second third
A 10 1.1
B 20 2.5
C 30 3.4
D 40 5.4
. . .
. . .
CodePudding user response:
import pandas as pd
data={'first':['A','B','C','D','E','F'],'second':[10,20,30,40,50,60],'third':[1.1,2.5,3.4,5.4,6.7,8.9]}
df = pd.DataFrame(data)
printf(df)
CodePudding user response:
Do it simply using pd.DataFrame()
OR pd.DataFrame.from_dict()
import pandas as pd
data=pd.DataFrame({'first':['A','B','C','D','E','F'],'second':[10,20,30,40,50,60],'third':[1.1,2.5,3.4,5.4,6.7,8.9]})
print(data)
OR
import pandas as pd
data={'first':['A','B','C','D','E','F'],'second':[10,20,30,40,50,60],'third':[1.1,2.5,3.4,5.4,6.7,8.9]}
data = pd.DataFrame.from_dict(data)
print(data)