Why is the result of the people variable the same as the result of the dfPeople dataframe, after adding the City column? What concept am I not understanding?
File people.csv
:
id,First Name,Last Name,Age
1,José,Pereira,40
2,João,Silva,33
3,Pedro,Campos,28
Reported problem code:
import pandas as pd
people = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/people.csv')
dfPeople = pd.DataFrame(people)
city = ['Mumbai','Beijing','New York']
dfPeople["City"] = city
I visualized the data in the following ways:
print(dfPeople)
dfPeople.head()
dfPeople
print(people)
people.head()
people
Proposed solutions to the problem based on the comments.
MattDMo's Solution:
import pandas as pd
people = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/people.csv')
city = ['Mumbai','Beijing','New York']
people["City"] = city
people.head()
Emma's Solution:
import pandas as pd
people = pd.read_csv('/content/drive/MyDrive/Colab Notebooks/people.csv')
dfPeople = pd.DataFrame(people.copy())
city = ['Mumbai','Beijing','New York']
dfPeople["City"] = city
#dfPeople.head()
people.head()