python pandas 在数据框列中添加列表作为默认值

Wil*_*lem 1 python pandas

我想在数据框 df 中创建一个新列,该列将填充所有行[np.nan]

    df['new'] = [np.nan]
Run Code Online (Sandbox Code Playgroud)

我明白了

ValueError: Length of values does not match length of index
Run Code Online (Sandbox Code Playgroud)

如果我尝试

    test['new'] = np.nan
    test['new'] = test['new'].astype('object')
    test['new'] = [np.nan]
Run Code Online (Sandbox Code Playgroud)

我明白了

ValueError: Length of values does not match length of index
Run Code Online (Sandbox Code Playgroud)

我想确保所有行都填充了包含以下内容的列表nan

WeN*_*Ben 5

您被分配一个object

df['New']=[[np.nan]]*len(df)
df
Out[250]: 
        Date  Value    New
0 2017-01-01      1  [nan]
1 2017-02-13      2  [nan]
2 2018-03-01      3  [nan]
3 2018-04-01      4  [nan]
Run Code Online (Sandbox Code Playgroud)