Question

In: Computer Science

build a python program that will be performing: - Read a CSV file 'annual.csv' enterprise into...

build a python program that will be performing:

- Read a CSV file 'annual.csv' enterprise into a data structure

- Count the number of rows and columns

- Determine if the data contains empty values

- Replace the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats

- Transform all Upper case characters to Lower case characters

- Transform all Lower case characters to Upper case characters

- save back the 'repaired' array as csv

- Print out the size of the data (number of rows, number of columns)

Difficulty:

-- be sure that each row has the same length (number of elements)

- the length of each row should be the same as the header.

Solutions

Expert Solution

The below code done using Pandas and numpy library in Python:

importing pandas and numpy:

import pandas as pd
import numpy as np


- Reading CSV file:

 annual = pd.read_csv(r"annual.csv")

- Counting the number of rows and columns

print(annual.shape())

-Determining if the data contains empty values:

Prints number of column wise null values :

print(annual.isnull().sum())

- Replacing the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats

a1 = annual.select_dtypes(include = 'int64')
a1.fillna("0", inplace = True) 

a2 = annual.select_dtypes(include = 'float64')
a2.fillna("0.0",inplace=True)

a3 = annual.select_dtypes(include = 'object')
a3.fillna("na",inplace=True)

- Transform all Upper case characters to Lower case character

annual.str.lower()

-Transform all Lower case characters to Upper case characters

annual.str.upper()

-save back the 'repaired' array as csv

repaired.to_csv('repaired.csv')

-Print out the size of the data (number of rows, number of columns):

print(annual.shape())

be sure that each row has the same length (number of elements) the length of each row should be the same as the header :

for this we have remove rows with null values:

annual=annual.dropna()

Related Solutions

Goal: to write a Python program that will read a playlist from a CSV file and...
Goal: to write a Python program that will read a playlist from a CSV file and display it in the console in the form of a table. https://s3.eu-west-2.amazonaws.com/bb-python-modules/Coursework/CW3/playlist_text_question.html The following is a link to the question. It includes all instruction and a template file (with additional instructions) where the answer must be completed.
Using Python read dataset in the HTML in beautiful way. You need to read CSV file...
Using Python read dataset in the HTML in beautiful way. You need to read CSV file ( Use any for example, You can use small dataset) You need to use pandas library You need to use Flask Make search table like YouTube has.
Write a Java program to read in the 10 numbers in the example file Book1.csv provided...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided above. The program should sum all the numbers, find the lowest number, find the highest number, and computer the average. Upon completion of the processing, the program should write a new text file named stats.txt with the information found in the following format where xxx represents a number calculated above. The sum of the numbers is: xxx The lowest number is: xxx The highest...
* readCsvFile() -- Read in a CSV File and return a list of entries in that...
* readCsvFile() -- Read in a CSV File and return a list of entries in that file.    * @param filePath -- Path to file being read in.    * @param classType -- Class of entries being read in.    * @return -- List of entries being returned.    */    public <T> List<T> readCsvFile(String filePath, Class<T> classType){        return null;    } implement this class. Return a list of T type. dont worry about CSV format. Just assume...
Write a program in python to read from a file the names and grades of a...
Write a program in python to read from a file the names and grades of a class of students to calculate the class average, the maximum, and the minimum grades. The program should then write the names and grades on a new file identifying the students who passed and the students who failed. The program should consist of the following functions: a) Develop a getGrades() function that reads data from a file and stores it and returns it as a...
Problem 9 - PYTHON There is a CSV-formatted file called olympics2.csv. Write code that creates a...
Problem 9 - PYTHON There is a CSV-formatted file called olympics2.csv. Write code that creates a dictionary named country_olympians where the keys are country names and the values are lists of unique olympians from that country (no olympian's name should appear more than once for a given country). Name,Sex,Age,Team,Event,Medal A Dijiang,M,24,China,Basketball,NA A Lamusi,M,23,China,Judo,NA Gunnar Nielsen Aaby,M,24,Denmark,Football,NA Edgar Lindenau Aabye,M,34,Sweden,Tug-Of-War,Gold Christine Jacoba Aaftink,F,21,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,21,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,25,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,25,Netherlands,Speed Skating,NA Christine Jacoba Aaftink,F,27,Netherlands,Speed Skating,NA Christine...
Step by step in python please Write a program this will read a file (prompt for...
Step by step in python please Write a program this will read a file (prompt for name) containing a series of numbers (one number per line), where each number represents the radii of different circles. Have your program output a file (prompt for name) containing a table listing: the number of the circle (the order in the file) the radius of the circle the circumference the area of the circle the diameter of the circle Use different functions to calculate...
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
Python DESCRIPTION Write a program that will read an array of integers from a file and...
Python DESCRIPTION Write a program that will read an array of integers from a file and do the following: ● Task 1: Revert the array in N/2 complexity time (i.e., number of steps) . ● Task 2: Find the maximum and minimum element of the array. INPUT OUTPUT Read the array of integers from a file named “ inputHW1.txt ”. To do this, you can use code snippet from the “ file.py ” file. This file is provided in Canvas....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT