base:
import pandas as pd
data = pd.DataFrame.from_dict({
'Name': ['Nik', 'Kate', 'Evan', 'Kyra'],
'Age': [31, 30, 40, 33],
'Location': ['Toronto', 'London', 'Kingston', 'Hamilton']
})
df = pd.DataFrame(data)
df
|
Name |
Age |
Location |
0 |
Nik |
31 |
Toronto |
1 |
Kate |
30 |
London |
2 |
Evan |
40 |
Kingston |
3 |
Kyra |
33 |
Hamilton |
solution:
import pandas as pd
data = pd.DataFrame.from_dict({
'Name': ['Nik', 'Kate', 'Evan', 'Kyra'],
'Age': [31, 30, 40, 33],
'Location': ['Toronto', 'London', 'Kingston', 'Hamilton']
})
df = pd.DataFrame(data)
# Using pandas.concat() to add a row
r = pd.DataFrame({'Name':'Creuza', 'Age':69, 'Location':'São Gonçalo'}, index=[0])
df2 = pd.concat([r,df.loc[:]]).reset_index(drop=True)
df2
|
Name |
Age |
Location |
0 |
Creuza |
69 |
São Gonçalo |
1 |
Nik |
31 |
Toronto |
2 |
Kate |
30 |
London |
3 |
Evan |
40 |
Kingston |
4 |
Kyra |
33 |
Hamilton |