There two sources of data that need to be merged :   population_df = pd.read_csv('https://raw.githubusercontent.com/Explore-AI/Public-Data/master/AnalyseProject/world_population.csv', index_col='Country Code')   meta_df = pd.read_csv('https://raw.githubusercontent.com/Explore-AI/Public-Data/master/AnalyseProject/metadata.csv', index_col='Country Code')   Your solution has one source of data (i.e.  data = pd.read_csv('world_population.csv') The solution does not give the expected output

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

There two sources of data that need to be merged :

 

population_df = pd.read_csv('https://raw.githubusercontent.com/Explore-AI/Public-Data/master/AnalyseProject/world_population.csv', index_col='Country Code')

 

meta_df = pd.read_csv('https://raw.githubusercontent.com/Explore-AI/Public-Data/master/AnalyseProject/metadata.csv', index_col='Country Code')

 

Your solution has one source of data (i.e.  data = pd.read_csv('world_population.csv')

The solution does not give the expected output

 

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Coded as advised:

import numpy as np
import pandas as pd

def get_total_pop_by_income(income_group_name='Low income'):
    population_df = pd.read_csv('https://raw.githubusercontent.com/Explore-AI/Public-Data/master/AnalyseProject/world_population.csv', index_col='Country Code')
    meta_df = pd.read_csv('https://raw.githubusercontent.com/Explore-AI/Public-Data/master/AnalyseProject/metadata.csv', index_col='Country Code')

    # Merge population and metadata dataframes
    df = pd.merge(population_df, meta_df[['Income Group']], left_index=True, right_index=True)

    # Filter by income group
    df = df[df['Income Group'] == income_group_name]

    if len(df) == 0:
        raise ValueError(f"No data found for income group {income_group_name}")

    # Convert year and population columns to numpy arrays

    year_col = df.columns.values[range(0, len(df.columns.values), 2)]
    population_col = df.columns.values[range(1, len(df.columns.values), 2)]
    year_array = np.array(year_col, dtype=np.int64)
    population_array = np.array(df[population_col], dtype=np.int64)

    # Stack arrays horizontally
    result = np.hstack((year_array.reshape(-1, 1), population_array))

    return result

 

Calling the function :

 

data =get_total_pop_by_income('High income')

 

Error message :-

 

 
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Input In [473], in <cell line: 1>() ----> 1 data =get_total_pop_by_income('High income') Input In [472], in get_total_pop_by_income(income_group_name) 19 year_col = df.columns.values[range(0, len(df.columns.values), 2)] 20 population_col = df.columns.values[range(1, len(df.columns.values), 2)] ---> 21 year_array = np.array(year_col, dtype=np.int64) 22 population_array = np.array(df[population_col], dtype=np.int64) 24 # Stack arrays horizontally ValueError: invalid literal for int() with base 10: 'Income Group'
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Elements of Tables
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education