You need numpy.reshape :
columns=['age','gender','height', 'weight','ap_hi','ap_lo', 'cholesterol','gluc','smoke', 'alco','active'] a = np.array([35,2,160,56,120,80,1,1,0,0,1]) df = pd.DataFrame(a.reshape(-1, len(a)),columns=columns) print (df) age gender height weight ap_hi ap_lo cholesterol gluc smoke alco \ 0 35 2 160 56 120 80 1 1 0 0 active 0 1
If the change operation is fuzzy to read, a more explicit way to add the dimension to the 1d array is to use numpy.atleast_2d
pd.DataFrame(np.atleast_2d(a), columns=columns)
Or itβs easier to add [] (but slower if there are really many columns):
df = pd.DataFrame([a],columns=columns) print (df) age gender height weight ap_hi ap_lo cholesterol gluc smoke alco \ 0 35 2 160 56 120 80 1 1 0 0 active 0 1
Thanks to Divakar for the suggestion :
df = pd.DataFrame(a[None],columns=columns) print (df) age gender height weight ap_hi ap_lo cholesterol gluc smoke alco \ 0 35 2 160 56 120 80 1 1 0 0 active 0 1
And one more solution, thanks piRSquared :
pd.DataFrame([a], [0], columns)