My code:
import pandas as pd
import numpy as np
d = {'one':[1,1,1,1,1],'two':[2,2,2,2,2],'letter':['a','a','b','b','c']}
e = np.array(d)
df = pd.DataFrame(e)
Throws this error:
ValueError: Must pass 2-d input
My code:
import pandas as pd
import numpy as np
d = {'one':[1,1,1,1,1],'two':[2,2,2,2,2],'letter':['a','a','b','b','c']}
e = np.array(d)
df = pd.DataFrame(e)
Throws this error:
ValueError: Must pass 2-d input
You don't need the e=np.array(d)
. The data
parameter in the dataframe constructor accepts properly formatted dictionaries.
Just use
df = pd.Dataframe(d)
Output:
letter one two
0 a 1 2
1 a 1 2
2 b 1 2
3 b 1 2
4 c 1 2