-1
I’m working on a chart that involves a file. csv, my question is what would be the best way to print a chart with 3 bars grouped for each country/country that contains: Median_wealth, Mean_wealth and Population. Follow my code, what it is printing and the contents of the CSV file:
Code:
import matplotlib.pyplot as plt
import csv
with open('wealth-per-country.csv', 'r', newline="") as arq:
reader = csv.reader(arq)
next(reader)
for column in csv.reader(arq):
if column:
print(f"Country: {column[0]}, \nMedian_Wealth: {column[1]}, \nMean_Wealth: {column[2]}, \nPopulation: {column[3]}")
Printa:
Country: Switzerland,
Median_Wealth: 227,891,
Mean_Wealth: 564,653,
Population: 6,866
Country: Australia,
Median_Wealth: 181,361,
Mean_Wealth: 386,058,
Population: 18,655
Country: Iceland,
Median_Wealth: 165,961,
Mean_Wealth: 380,868,
Population: 250
Country: Hong Kong,
Median_Wealth: 146,887,
Mean_Wealth: 489,258,
Population: 6,267
Country: Luxembourg,
Median_Wealth: 139,789,
Mean_Wealth: 358,003,
Population: 461
Country: Belgium,
Median_Wealth: 117,093,
Mean_Wealth: 246,135,
Population: 8,913
Country: New Zealand,
Median_Wealth: 116,433,
Mean_Wealth: 304,124,
Population: 3,525
Country: Japan,
Median_Wealth: 110,408,
Mean_Wealth: 238,104,
Population: 104,963
Country: Canada,
Median_Wealth: 107,004,
Mean_Wealth: 294,255,
Population: 29,136
Country: Ireland,
Median_Wealth: 104,842,
Mean_Wealth: 272,310,
Population: 3,491
CSV:
Country,Median_Wealth,Mean_Wealth,Population
Switzerland,"227,891","564,653","6,866"
Australia,"181,361","386,058","18,655"
Iceland,"165,961","380,868",250
Hong Kong,"146,887","489,258","6,267"
Luxembourg,"139,789","358,003",461
Belgium,"117,093","246,135","8,913"
New Zealand,"116,433","304,124","3,525"
Japan,"110,408","238,104","104,963"
Canada,"107,004","294,255","29,136"
Ireland,"104,842","272,310","3,491"