创建一个DataFrame返回参数'index'的多个值

时间:2018-09-03 10:57:58

标签: python pandas

dframe1 = DataFrame[1,np.nan,2,np.nan], 
                   [np.nan,3,np.nan,4], 
                   [5,np.nan,6,np.nan], 
                   columns = ['a','b','c','d'], 
                   index=[1,2,3]).

错误:

  

init ()为参数'index'获得了多个值?

1 个答案:

答案 0 :(得分:0)

您需要通过[]创建嵌套列表:

dframe1 = pd.DataFrame([[1,np.nan,2,np.nan], 
                        [np.nan,3,np.nan,4], 
                        [5,np.nan,6,np.nan]], 
                         columns = ['a','b','c','d'], 
                         index = [1,2,3])
print (dframe1)

     a    b    c    d
1  1.0  NaN  2.0  NaN
2  NaN  3.0  NaN  4.0
3  5.0  NaN  6.0  NaN