You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now that the data frames have been concatenated, notice that the index is funky. It repeats the numbers 0 - 11 in the peoples republic of berkeley data.
Often we have more than one data frame that contains parts of our data set and we want to put them together. This is known as merging the data.
Our advisor now wants us to add a new country called The People's Republic of Berkeley to the gapminder data set that we have cleaned up. Our goal is to get this new data into the same data frame in the same format as the gapminder data and, in this case, we want to concatenate (add) it onto the end of the gapminder data.
Concatentating is a simple form of merging, there are many useful (and more complicated) ways to merge data. If you are interested in more information, the Pandas Documentation is useful.
bring in the People's Republic of Berkeley data
PRB = pd.read_table('PRB_data.csv', sep = "\t")
PRB
make this into an exercise
bring in PRB data (no major problems) and make it conform to the gapminder at this point
our version...
clean the data to look like the current gapminder
PRB['country']=PRB['region'].str.split('', 1).str[1].str.lower()
PRB['continent']=PRB['region'].str.split('', 1).str[0].str.lower()
PRB = PRB.drop('region', 1)
PRB.columns = PRB.columns.str.lower()
PRB = PRB.rename(columns={'life exp' : 'lifeexp'})
PRB
double check that the gapminder is the same
gapminder.head()
combine the data sets with concat
gapminder_comb = pd.concat([gapminder, PRB])
gapminder_comb
this is markdown
Now that the data frames have been concatenated, notice that the index is funky. It repeats the numbers 0 - 11 in the
peoples republic of berkeley data
.as an exercise fix the index.
our code for fixing index
gapminder_comb = gapminder_comb.reset_index(drop=True)
gapminder_comb
The text was updated successfully, but these errors were encountered: