V-MalM / Analysis-Using-Python

Read an individual csv file, analyze data, perform calculations, print summary of analysis to screen and also create an output text file and write summary of analysis to it.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Project Description --> This python project has two tasks:

PyBank and PyPoll , both read an individual csv file, analyze data, perform calculations, print summary of analysis to screen and also create an output text file and write summary of analysis to it.
  • Used Lists, Dictonaries, Tuples and Sets in both projects. Also used Functions and Error Handling with 'try..except..else..'
  • In PyBank, used TUPLE where required and datetime module , lamda function and sort() method to sort data.
  • In PyPoll, used SET where required. Used lambda funtion along with python sorted() function.
    • Instead of checking candidates name in a for loop to create a unique list of candidates, i used a set.
Explained in detail

1. PyBank

  • Created a Python script for analyzing the financial records of a company from a set of financial data 'budget_data.csv' that is composed of two columns: Date and Profit/Losses.The script analyzes the records to calculate each of the following:

    • The total number of months included in the dataset
    • The net total amount of "Profit/Losses" over the entire period
    • Calculate the changes in "Profit/Losses" over the entire period, then find the average of those changes
    • The greatest increase in profits (date and amount) over the entire period
    • The greatest decrease in losses (date and amount) over the entire period
    • Analysis looks similar to the one below:

Resources:

  • Folder PyBank : This folder contains two folders
    • 'Resources': Contains the financial data 'budget_data.csv'
    • 'analysis' : Folder to which the output text file with analysis, will be written.
    • Python file 'main.py' that has python script for analyzing the financial data stored in 'Resources/budget_data.csv'

Key notes:

  • Used csv.DictReader that reads the data from csv file and creates a dictonary preserving the header with each header field as a key.
  • Used 'from datetime import datetime' that imports a module 'datetime' to work with dates as date objects.
  • Used tuples to work with data for further analysis.
  • Used sort() method to sort and rearrange the list of tuples in order of date
  • Used lamda function to sort

Execution:

  • The script is in the file main.py which can be located in the folder PyBank.
  • Using PyBank as the working folder, run 'main.py'.
  • It has 2 functions readFromCsv(), and analyzeAndWrite()
  • The file has detailed comments explaining these functions and code outside the scope of functions

Results:

  • The following analysis is printed to the terminal and the same result is written to output text file 'analysis/budget_analysis.txt'

Important: Run 'main.py' from PyBank as current working direcory

eRRORS !!!! What ERRORS ????
  • Handled 'Filenotfound' errors in case the script cannot find the source or destination folders/file
  • Made sure 'ZeroDivisionError' doesn't occur
  • REST ASSURED, The code runs error free. Just Follow these detailed instructions ....

2. PyPoll

  • Created a Python script for helping a small, rural town modernize its vote counting process by analyzing poll data in 'election_data.csv' that is composed of three columns: Voter ID, County, and Candidate.This script analyzes the votes and calculates each of the following:

    • The total number of votes cast
    • A complete list of candidates who received votes
    • The percentage of votes each candidate won
    • The total number of votes each candidate won
    • The winner of the election based on popular vote.
    • Analysis looks similar to the one below:

Resources:

  • Folder PyPoll : This folder contains two folders
    • 'Resources': Contains poll data 'election_data.csv'
    • 'analysis' : Folder to which the output text file with analysis, will be written.
    • Python file 'main.py' that has python script for analyzing the election_data data stored in 'Resources/election_data.csv'

Key notes:

  • Used csv.DictReader that reads the data from csv file and creates a dictonary preserving the header with each header field as a key.
  • Used SET to create a unique list of candidates.
  • Used lamda function
  • Used sorted() function to sort and rearrange the date

Execution:

  • The script is in the file main.py which can be located in the folder PyPoll.
  • Using PyPoll as the working folder, run 'main.py'.
  • It has 2 functions readFromCsv(), and analyzeAndWrite()
  • The file has detailed comments explaining these functions and code outside the scope of functions

Results:

  • The following analysis is printed to the terminal and the same result is written to output text file 'analysis/election_results.txt'

Important: Run 'main.py' from PyPoll as current working direcory

eRRORS !!!! What ERRORS ????
  • Handled 'Filenotfound' errors in case the script cannot find the source or destination folders/file
  • Made sure 'ZeroDivisionError' doesn't occur
  • REST ASSURED, The code runs error free. Just Follow these detailed instructions ....

About

Read an individual csv file, analyze data, perform calculations, print summary of analysis to screen and also create an output text file and write summary of analysis to it.


Languages

Language:Python 100.0%