python - How to add new row in pandas dataframe?
问题描述
I have like this data frame
poke = pd.DataFrame(
{
'name': ['Bulbasaur', 'Ivysaur', 'Blastoise', 'Sandslash'],
'attack': [49, 62, 83, 100],
'type': ['grass', 'grass', 'water', 'ground']
}, columns=['name', 'attack', 'type']
)
And I want to add a new row for each pokemon, I have it in this dataframe
date = pd.DataFrame({'date': '11/22/12'}, index=[0])
I'm doing it this way
poke = pd.concat([poke, date], axis=1)
But it only adds for the first row and the others in NaN like this
Out[7]:
name attack type date
0 Bulbasaur 49 grass 11/22/12
1 Ivysaur 62 grass NaN
2 Blastoise 83 water NaN
3 Sandslash 100 ground NaN
Any ideas so that the date is repeated in the others?
解决方案
推荐阅读
- json - Kotlin - 数据类错误中的数组属性
- javascript - 如何将对象参数从 jQgrid 的格式化程序函数分配给函数?
- commercetools - 用于映射某些草稿的 Dsl 和 Builder 类有什么区别?
- node.js - 如何从命令行或 npm 库打印 PDF 文件?
- ios - 整页截图API(iOS13)
- flutter - 从不同的有状态小部件打开抽屉菜单
- android - Android,我需要从意图类型打开我的文件夹以获取内容吗?
- if-statement - 飞镖替代了很多 if elseiif
- arrays - 数组和列表长度未初始化
- python - 在 pip 安装期间运行安装脚本