asks the user to specify the input file, asks the user to specify the output fil
ID: 3735787 • Letter: A
Question
asks the user to specify the input file, asks the user to specify the output file, makes a plot of the fraction of the total population that are children over time from the data in input file, and stores the plot in the output file the user specified. A sample run of the program: Enter name of input file: DHS_2015_2016.csv Enter name of output file: dhsPlot.png which produces an output: 0.54 Fraction Children 052 0.5 0.48 0.46 .44 042 0.40 /2ors4/15/2ory/29/20m/05/2012/13/2015125/2019/04/2012/11/2016 Date of Census Note: The grading script is expecting that the label (i.e. name of your new column) is "Fraction Children"Explanation / Answer
Solution:
The below data is with respect to the .csv format which is as follows;
import csv """ importing csv file to read csv file """
def csv_reader(file_obj): """ function to read csv file """
reader = csv.reader(file_obj) """ this reader will have csv file data into it """
for row in reader: """ for each row in reader variable """
print(" ".join(row)) """ printing each column value by space saperated """
if _name_ == "__main__":
csv_path = "TB_data_dictionary_2014-02-26.csv" """ csv file name """
with open(csv_path, "rb") as f_obj: """ rb is read as byte object """
csv_reader(f_obj) """ calling csv_reader function with f_obj as parameter """
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.