Last active
July 24, 2023 20:43
-
-
Save kururu-abdo/3d9bb4c1c5845a918fe4b964e8660ce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np # useful for many scientific computing in Python | |
| import pandas as pd # primary data structure library | |
| %matplotlib inline | |
| import matplotlib as mpl | |
| import matplotlib.pyplot as plt | |
| ### type your answer here | |
| df_CI = df_can.loc[['India', 'China'], years] | |
| df_CI.index = df_CI.index.map(int) # let's change the index values of df_CI to type integer for plotting | |
| df_CI.plot(kind='line') | |
| plt.title('Immigrants from China and India') | |
| plt.ylabel('Number of Immigrants') | |
| plt.xlabel('Years') | |
| plt.show() | |
| /////////////////////////////////////////////////////////////////////////////////////////// | |
| inplace = True # paramemter saves the changes to the original df_can dataframe | |
| df_can.sort_values(by='Total', ascending=False, axis=0, inplace=True) | |
| # get the top 5 entries | |
| df_top5 = df_can.head(5) | |
| # transpose the dataframe | |
| df_top5 = df_top5[years].transpose() | |
| print(df_top5) | |
| #Step 2: Plot the dataframe. To make the plot more readeable, we will change the size using the `figsize` parameter. | |
| df_top5.index = df_top5.index.map(int) # let's change the index values of df_top5 to type integer for plotting | |
| df_top5.plot(kind='line', figsize=(14, 8)) # pass a tuple (x, y) size | |
| plt.title('Immigration Trend of Top 5 Countries') | |
| plt.ylabel('Number of Immigrants') | |
| plt.xlabel('Years') | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment