首页 > 编程语言 >python列表添加元素

python列表添加元素

时间:2023-08-19 12:33:31浏览次数:37  
标签:insert None python 列表 添加 np array append

列表添加元素

df_test = pd.DataFrame({'a':[1,2],'b':[3,None]})
df_test.columns + 'c'  # 每个元素拼接'c'!不能直接添加元素!

['a', 'b'] + ['c']  # 不能每个元素拼接, 也不能直接加字符串, 需要列表+列表进行扩展, 且append输出为None

# np.array 不能直接使用"+"  UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U1'), dtype('<U1')) -> None
np.append(np.array(['a', 'b']), 'c')
np.append(np.array(['a', 'b']), ['c'])
np.append(['a', 'b'], 'c')
np.append(['a', 'b'], ['c'])

np.insert(np.array(['a', 'b']), 2, 'c')
np.insert(np.array(['a', 'b']), 2, ['c'])
np.insert(['a', 'b'], 2, 'c')
np.insert(['a', 'b'], 2, ['c'])

标签:insert,None,python,列表,添加,np,array,append
From: https://blog.51cto.com/u_16055028/7148370

相关文章