首页 > 解决方案 > 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?

标签: pythonpython-3.xpandas

解决方案


推荐阅读