<jupyter_start><jupyter_text>Exercise 5 Step 1. Load the cities (not the swapped version) CSV file created in exercise 4.<jupyter_code># Step 1 Solution

import pandas as pd

cities = pd.read_csv("cities.csv", index_col=0)<jupyter_output><empty_output><jupyter_text>Step 2. Use head to display the first three rows.<jupyter_code># Step 2 Solution

cities.head(3)<jupyter_output><empty_output><jupyter_text>Step 3. Use tail to display the last three rows.<jupyter_code># Step 3 Solution

cities.tail(3)<jupyter_output><empty_output><jupyter_text>Step 4. Display the row for Phoenix using the label.<jupyter_code># Step 4 Solution

cities.loc[ ["Phoenix"] ]<jupyter_output><empty_output><jupyter_text>Step 5. Display the row for Phoenix using the row index.<jupyter_code># Step 5 Solution

# cities
# cities.iloc[ [4] ]

# cities.loc[["Phoenix"]]

# cities.index[ cities["pop2020"] == 8253213 ]

# cities.index[ ["Phoenix"] ]

import numpy as np

idx_results = np.where(cities.index.values == "Phoenix")
idx = idx_results[0][0]
cities.iloc[ [idx] ]


cities.iloc[ [ cities.index.get_loc("Phoenix") ] ]<jupyter_output><empty_output><jupyter_text>Step 6. How many cities experienced negative growth from 2010 to 2020?<jupyter_code># Step 6 Solution

cities[cities["pop change"] < 0]<jupyter_output><empty_output><jupyter_text>Step 7. Display Chicago to Houston using a range of labels.<jupyter_code># Step 7 Solution

cities[ "Chicago":"Phoenix" ]<jupyter_output><empty_output><jupyter_text>Step 8. Display Chicago to Houston using a range of indexes.<jupyter_code># Step 8 Solution

cities.iloc[2:5]<jupyter_output><empty_output><jupyter_text>Step 9. Display descriptive statistics for the data frame.<jupyter_code># Step 9 Solution

cities.describe()<jupyter_output><empty_output><jupyter_text>Step 10. Use a pie chart to show the 2020 estimated population of each city relative to the other cities in the data frame.<jupyter_code># Step 10 Solution

from matplotlib import pyplot as plt
%matplotlib inline

# def actualvalue(val):
#   return "%.2f" % val

fig_1 = plt.figure(1, figsize=(10, 10), facecolor="white")

ax1 = fig_1.add_subplot(111)

ax1.pie(
  # cities[ ["pop2020"] ].values[:,0],
  cities["pop2020"].values,
  labels=cities.index.values,
  autopct='%1.1f%%',
#   autopct=actualvalue
)
ax1.axis('equal')


plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12425784563189143, 'fraction_numerical': 0.03435114503816794, 'mean_word_length': 6.192073170731708, 'pattern_counts': {'":': 1, '<': 42, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '460529', 'license': 'MIT', 'n_tokens_mistral': 922, 'n_tokens_neox': 851, 'n_words': 219, 'path': 'jupyter_labs_conda/exercises/05_Exercise.ipynb', 'repo_name': 't4d-classes/python-data-analysis_06022021', 'size': '2358'}