Write an open_file() and a function that reads a csv data file and returns a dictionary


If you have any doubts, please give me comment...


Code:
import csv
def open_file():
is_open = False
while is_open == False:
fname = input("Enter input filename: ")
try:
fp = open(fname)
is_open = True
except FileNotFoundError:
print("Unable to open", fname)
return fp
def build_dictionary(fp):
my_dict = {}
fp.readline()
csv_r = csv.reader(fp, delimiter=',')
for row in csv_r:
country = row[2]
area = row[1]
last_update = row[3]
cases = int(row[4])
deaths = int(row[5])
recovered = int(row[6])
if country not in my_dict:
my_dict[country] = []
my_dict[country].append({area:(last_update, cases, deaths, recovered)})
return my_dict
fp = open_file()
print(build_dictionary(fp))
Write an open_file() and a function that reads a csv data file and returns a dictionary...
write a function: Names(path): that reads from a file at location path and returns a dictionary mapping from column names to lists containing the data in those columns. The format of the file is a csv file. The first line is a comma separated set of string names for the columns contained in the file. The function will accumulate a dictionary mapping from year to the list of years, from name to the list of names (in the same order),...
Write a function named "loadStateDict(filename) that takes a filename and returns a dictionary of 2-character state codes and state names. The file has four columns and they are separated by commas. The first column is the state full name and the second column is the state code. You don't have to worry about column 3 & 4. You should eliminate any row that is without a state code. Save the two columns into a dictionary with key = state code...
Using C# or Python, write a code that reads a Microsoft Excel CSV file named "LabAssignment" then outputs all the collected and formated data as another Microsoft Excel CSV file named "labOutput" The CSV file contains 25 colums as well close to 200 rows of data. Write a code in C# or Python so that: It removes all unwanted columns along with its data...the columns that should be kept have the following header: "User" "Location" "Feature" "HoursUsed" Remove all files...
Define a Python function named borough_count
that has one parameter. The parameter is a string representing the
name of a CSV file. The CSV file is a subset of NYC's dataset of
all film permits issued since April 2016. Each row in the CSV file
has the format:
Event Id, Police Precinct(s), Event Type, Borough, Category
Your function must return a dictionary. The keys of this dictionary
will be the boroughs read in from the file (boroughs are at index...
In Any Language write a function to loop through a csv file (10 rows no headers) and pull out the data from the 3rd column (string). Create one string with those values separated by commas in arranged in alphabetical order by the first letter (example: “Amazon, Aaron, Base, …..”, Amazon and Aaron do not need to be reversed). It can be assumed the csv file is already read into a variable. Please provide comments.
Part 2: Preperation for ML algorithms %run part2-setup.py 7. Write the function prepare_data(dataset_dict), which takes a dataset dictionary and returns a tuple (X,y) that holds the datamatrix and the labels In [3] : .Both X and y are of type numpy arrays . If the output variable is numeric (np.issubdtype(y.dtype, np.number)) it should be kept as is, otherwise it should be discretized using the command pandas.factorize) (use default function parameters). .Categorical features (whose columns are specified in the configuration file)...
Python Assignment In this assignment, you will use Pandas library to perform analysis on the dataset stored in the following csv file: breast-cancer-wisconsin.csv. Please write script(s) to do the following: 1. Read the csv file and covert the dataset into a DataFrame object. 2. Persist the dataset into a SQL table and a JASON file. • Write the content of the DataFrame object into an SQLite database table. This will convert the dataset into a SQL table format. You can...
Implement a class CSVReader that reads a CSV file, and provide methods: int numbOfRows() int numberOfFields(int row) String field(int row, int column) Please use the CSVReader and CSVReaderTester class to complete the code. I have my own CSV files and cannot copy them to here. So if possible, just use a random CSV file. CSVReader.java import java.util.ArrayList; import java.util.Scanner; import java.io.*; /** Class to read and process the contents of a standard CSV file */ public class CSVReader {...
According to Wikipedia , a comma-separated values (CSV) file is a delimited text file that uses a comma to separate values. A CSV file stores tabular data (numbers and text) in plain text. Each line of the file is a data record. Each record consists of one or more fields, separated by commas. The use of the comma as a field separator is the source of the name for this file format. A company has text data that is not...
A csv file called COS-206_gradebook.csv is provided for this project (see Course Documents). This file contains grades data for 17 students on 20 assessments. These assessments include quizzes, homework assignments, term projects, and tests.First you are strongly encouraged to open this file in Excel to gain an overview of the data. Note the second row contains point totals for the assessments. For instance, the point total for hw0 (Homework 0) is 20 while the point total for hw1 (Homework 1)...