import pandas as pd
data={'X':45, 'Y':12,'Z':85}
df=pd.DataFrame(data)
print(df)
TypeError: 'dict' object is not callable
import pandas as pd
data={'X':45, 'Y':12,'Z':85}
df=pd.DataFrame(data)
print(df)
TypeError: 'dict' object is not callable
You are passing scalar values, you have to pass an index. So you can either not use scalar values for the columns. try this:
import pandas as pd
data={'X':[45], 'Y':[12],'Z':[85]}
df=pd.DataFrame(data)
print(df)
or pass an index for scalar values like this :
import pandas as pd
data={'X':45, 'Y':12, 'Z':85}
df=pd.DataFrame(data, index=[0])
print(df)
import pandas as pd
data=[{'X':45, 'Y':12,'Z':85}]
df=pd.DataFrame(data)
print(df)
There are many creation methods that have slightly different parameter values, so it depends what format you are expecting. Simple solution:
df = pd.Series(data).to_frame()
dataframe format:
0
X 45
Y 12
Z 85
or df.T
:
X Y Z
0 45 12 85
To create DataFrame from dict of narray/list, all the narray must be of same length. If index is passed then the length index should be equal to the length of arrays. If no index is passed, then by default, index will be range(n) where n is the array length. You should do like following-
import pandas as pd
data={'X':[45], 'Y':[12],'Z':[85]}
df=pd.DataFrame(data)
print(df)