0% found this document useful (0 votes)
12 views2 pages

Matplot Question1

The document contains a Python script that creates a DataFrame with population and birth rate data for six countries. It displays specific data for China, India, Brazil, and Pakistan, saves the DataFrame to a CSV file, and generates a bar chart to visualize the population of the countries. The script utilizes the pandas and matplotlib libraries for data manipulation and visualization.

Uploaded by

Aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Matplot Question1

The document contains a Python script that creates a DataFrame with population and birth rate data for six countries. It displays specific data for China, India, Brazil, and Pakistan, saves the DataFrame to a CSV file, and generates a bar chart to visualize the population of the countries. The script utilizes the pandas and matplotlib libraries for data manipulation and visualization.

Uploaded by

Aditya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

import pandas as pd

import [Link] as plt

# 1. Create DataFrame
country = [Link]({
"Country": ["China","India","United States","Indonesia","Brazil","Pakistan"],
"Population":
[1379750000,1330780000,324882000,260581000,206918000,194754000],
"BirthRate": [12.00,21.76,13.21,18.84,18.43,27.62],
"UpdateDate": ["2016-08-11","2016-08-11","2016-08-11","2016-01-07","2016-
08-11","2016-08-11"]
})

print("Original DataFrame:\n", country)

# 2. Display complete data for China and India


print("\nData for China and India:\n")
print(country[country["Country"].isin(["China", "India"])])

# 3. Display Country, Population, BirthRate of Brazil and Pakistan


print("\nCountry, Population and BirthRate for Brazil and Pakistan:\n")
print([Link][country["Country"].isin(["Brazil", "Pakistan"]),
["Country","Population","BirthRate"]])

# 4. Save to CSV file


country.to_csv("[Link]", index=False)
print("\nCSV file '[Link]' created successfully!")

# 5. Plot Bar Chart (Country vs Population)


[Link](country["Country"], country["Population"], color="lightgreen",
edgecolor="black")
[Link]("Population of Countries")
[Link]("Country")
[Link]("Population")
[Link](True, linestyle="--", alpha=0.6)
[Link]()

You might also like