My questions are about this project
https://www.codecademy.com/paths/data-analyst-training-for-your-business-cfb/tracks/dacp-data-wrangling-and-tidying/modules/dscp-data-cleaning-with-pandas/projects/data-cleaning-us-census
When we want to replace a column in a dataframe we can do it two ways. For instance if we want to remove the “$” from the income column we can do any of these two options
1. us_census.Income = us_census.Income.str.replace("[$]", '', regex=True)
Income = []
2. for i in range(0, len(us_census.Income)):
string = str(us_census.Income.iat[i])
replace = string.replace('$', "")
Income.append(replace)
df['new_column']= Income
What is the difference between these two approaches and why there are some cases which we can’t use the first approach?
For instance if we want to break the column GenderPop and create two new columns for men and women we can’t use the first approach.