PYTHON + DATAFRAMES (pandas) import pandas as pd crimeData = {'agency_code': ['UT01803','TXSPD00','CA03711','MOSPD00','NY05101'], 'location': ['Salt Lake City, UT','San Antonio, TX','San Diego, CA','St. Louis, MO','Suffolk County, NY'], 'population': [191992,1463586,1400467,317095,1341453], 'homicides': [8,94,37,188,24], 'assaults': [874,5465,3601,3521,895], 'robberies': [469,1986,1378,1790,677]} df = pd.DataFrame(crimeData) df.set_index('agency_code', inplace=True) homicidesPerCapita = {'homicides_per_capita':[4,6,3,59,2,9]} df2 = pd.DataFrame(homicidesPerCapita) df3 = df.join(df2) df3 Questions: Why is printing homicides_per_capita as NaN? Sort the DataFrame by homicides per capita from greatest to least on the original DataFrame Filter/reduce the DataFrame down to only those with more than 50 total homicides OR (not 'and') over 5000 assaults Print the DataFrame Thanks!
PYTHON + DATAFRAMES (pandas) import pandas as pd crimeData = {'agency_code': ['UT01803','TXSPD00','CA03711','MOSPD00','NY05101'], 'location': ['Salt Lake City, UT','San Antonio, TX','San Diego, CA','St. Louis, MO','Suffolk County, NY'], 'population': [191992,1463586,1400467,317095,1341453], 'homicides': [8,94,37,188,24], 'assaults': [874,5465,3601,3521,895], 'robberies': [469,1986,1378,1790,677]} df = pd.DataFrame(crimeData) df.set_index('agency_code', inplace=True) homicidesPerCapita = {'homicides_per_capita':[4,6,3,59,2,9]} df2 = pd.DataFrame(homicidesPerCapita) df3 = df.join(df2) df3 Questions: Why is printing homicides_per_capita as NaN? Sort the DataFrame by homicides per capita from greatest to least on the original DataFrame Filter/reduce the DataFrame down to only those with more than 50 total homicides OR (not 'and') over 5000 assaults Print the DataFrame Thanks!
New Perspectives on HTML5, CSS3, and JavaScript
6th Edition
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Patrick M. Carey
Chapter14: Exploring Object-based Programming: Designing An Online Poker
Section14.1: Visual Overview: Custom Objects, Properties, And Methods
Problem 7QC
Related questions
Topic Video
Question
PYTHON + DATAFRAMES (pandas)
import pandas as pd
crimeData = {'agency_code': ['UT01803','TXSPD00','CA03711','MOSPD00','NY05101'],
'location': ['Salt Lake City, UT','San Antonio, TX','San Diego, CA','St. Louis, MO','Suffolk County, NY'],
'population': [191992,1463586,1400467,317095,1341453],
'homicides': [8,94,37,188,24],
'assaults': [874,5465,3601,3521,895],
'robberies': [469,1986,1378,1790,677]}
df = pd.DataFrame(crimeData)
df.set_index('agency_code', inplace=True)
homicidesPerCapita = {'homicides_per_capita':[4,6,3,59,2,9]}
df2 = pd.DataFrame(homicidesPerCapita)
df3 = df.join(df2)
df3
Questions:
Why is printing homicides_per_capita as NaN?
Sort the DataFrame by homicides per capita from greatest to least on the original DataFrame
Filter/reduce the DataFrame down to only those with more than 50 total homicides OR (not 'and') over 5000 assaults
Print the DataFrame
Thanks!
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning