Im trying to add a Series to my DataFrame with the append funtion. I'm not trying to permanently change the DataFrame, this is just for study purposes. I get a traceback that 'DataFrame' object has no attribute 'append'.
My DataFrame:
df = pd.DataFrame({
'Population': [35.467, 63.951, 80.94, 60.665, 127.061, 64.511, 318.523],
'GDP': [
1785387,
2833687,
3874437,
2167744,
4602367,
2950039,
17348075
],
'Surface Area': [
9984670,
640679,
357114,
301336,
377930,
242495,
9525067
],
'HDI': [
0.913,
0.888,
0.916,
0.873,
0.891,
0.907,
0.915
],
'Continent': [
'America',
'Europe',
'Europe',
'Europe',
'Asia',
'Europe',
'America'
]
}, columns=['Population', 'GDP', 'Surface Area', 'HDI', 'Continent'])
What im trying to add:
df.append(pd.Series({
'Population': 3,
'GDP': 5
}, name='China'))
The Attribute Error:
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_9724\2859580344.py in ?()
----> 1 df.append(pd.Series({
2 'Population': 3.,
3 'GDP': 5
4 }, name='China'))
~\AppData\Roaming\Python\Python310\site-packages\pandas\core\generic.py in ?(self, name)
5985 and name not in self._accessors
5986 and self._info_axis._can_hold_identifiers_and_holds_name(name)
5987 ):
5988 return self[name]
-> 5989 return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'append'
I already tried to update pandas, but its running on the newest version. I closed Vscode and ran all again. Nothing has changed.
What I'm expecting: