Question

In: Computer Science

need to write program on python, without using any other libraries like panda, numpy, etc. here...

need to write program on python, without using any other libraries like panda, numpy, etc.

here is google link on csv file https://drive.google.com/file/d/1O3cC9JAPVkXSrddTR6RocpSV8NMHrmRx/view?usp=sharing

There is a csv file, which is exel file, very big and what program should do:

- 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 (should search in all rows)

- Replace the empty values by 'NA' for strings, '0' for decimals and '0.0' for floats (in all rows)

- Transform all Upper case characters to Lower case characters (in every word)

- Transform all Lower case characters to Upper case characters (in every word in file)

- save back the 'repaired' array as csv and show edited version

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

the file approzimately looks like this, but it is very huge

Solutions

Expert Solution

Code for above problem :-

import csv
# function to change the upper case to lower case or vice versa
def change(string):
    new =''
    for i in string:
        # Checking for lowercase letter and converting to uppercase.
        if (i.isupper()) == True:
            new += (i.lower())
            # Checking for uppercase letter and converting to lowercase.
        elif (i.islower()) == True:
            new += (i.upper())
            # everything other than alphabet added as it is
        else:
            new += i
    return new
# Data structure to store the imported data and edit
repaired = []
# reading from csv module
with open('annual.csv','r') as file:
    data = csv.reader(file)
    for row in data:
        repaired.append(row)
# calculating no of rows
row_len = len(repaired)
# calculating no of columns
column_len = len(repaired[0])
#  editing data
for i in range(1,row_len):
    # Adding 0 to the cell that contains numerical values if empty
    if repaired[i][8] == '':
        repaired[i][8] = '0'
    for j in range(column_len):
        # Adding NA to the cell that contains string values if empty
        if repaired[i][j]=='':
            repaired[i][j]=='NA'
        # calling function to change upper to lower or vice versa
        string = repaired[i][j]
        repaired[i][j] = change(string)
#  creating another csv file of edited data
with open('repaired.csv','w',newline='') as file:
    writer = csv.writer(file)
    writer.writerows(repaired)
#  print no of rows and columns
print("No. of Rows = ",row_len)
print("No. of Columns = ",column_len)

Screenshot for Code and Output :-

Screenshot of repaired.csv dataset:-


Related Solutions

Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x...
Write a python code without using Sympy and Numpy to derive the polynomial 2x2 + 5x + 4.
I need the following problem to be coded in python without using Numpy: Given input features...
I need the following problem to be coded in python without using Numpy: Given input features x1​, x2​,..., xi​ and corresponding weights w0​, w1​, w2​,...wi​. Write a function, called 'Perceptron', that returns the output value yi. For your function, use the following perceptron activation function: g(X,W)={1 if wTx>0;0 otherwise} The inputs X and W will be arrays of the input feature and weight values, respectively. All values will be integers. Your function will return gp​(X,W), which is a single integer...
Write a python function (Without using external libraries) to calculate the 1). determinate of a 2...
Write a python function (Without using external libraries) to calculate the 1). determinate of a 2 x 2 matrix 2). Calculate the inverse of a 2 x 2 matrix.
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python...
Create and Compile a Python Script without using Numpy that Generate an nxn matrix using Python Script (ie n=user input) Ask (user input ) and (randomly generated) row and column location Assign Q to (known row and column location ) and 0 to all others location Please show compile script working as well
Need to able to solve this method WITHOUT using ANY java libraries. ------------------------------ import java.util.Scanner; public...
Need to able to solve this method WITHOUT using ANY java libraries. ------------------------------ import java.util.Scanner; public class nthroot { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // Read n (for taking the nth root) int num = Integer.parseInt(sc.nextLine());    // Read number to take the nth root of int number = Integer.parseInt(sc.nextLine());    // Read the desired precision int precision = Integer.parseInt(sc.nextLine());    // Print the answer System.out.println(findnthRoot(number, num, precision)); }    private static String...
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data...
I'm working on a scatter-plot program in Python using Pandas, Matplotlib, Numpy, etc. I'm pulling data from a CSV file, which has no names, just numbers. All I did was to read a .csv file. How do I pull data from three columns which contains about 1500 rows with just numbers and make a scatter plot with two in the x-axis and the third in the y-axis?
#Python program using loop instead of numpy or pandas. Write a function to enter n student...
#Python program using loop instead of numpy or pandas. Write a function to enter n student scores from 0 to 100 to represent student score, Count how many A (100 - 90), B(89-80), C(79-70), D(69-60), F(<60) We will use numpy array OR pandas later for this problem, for now use loop Invoke the function with 10 student scores, show the result as follow: Test Enter 10 scores Enter a student score: 99 Enter a student score: 88 Enter a student...
Discuss any API / libraries of your favorite programming language (e.g. python, c#, java etc.) that...
Discuss any API / libraries of your favorite programming language (e.g. python, c#, java etc.) that you have used/reused in any of your previous projects and how it contributes to the overall project.
I need to write PYTHON program which is like a guessing game using randint function which...
I need to write PYTHON program which is like a guessing game using randint function which is already done, the user has to guess a number between 1 and 1000 and the game musn't end until you guess the number, if you input a smaller number you must get hints, the same goes if your input is bigger than the wining number , also you must get notified if you repeat a number (example, you pick 1 and in the...
Write a python code that calculates π using numpy rand function.
Write a python code that calculates π using numpy rand function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT