Question

Using python beginner code see example code of what to use for this assignment we have...

Using python beginner code see example code of what to use for this assignment

we have gathered together some interesting data into a file called harvardLightning.txt

The file contains all recorded lightning strikes in the harvard area

Parsing

Review alist = str.split()                  # alist will contain the elements of str - split using whitespace

Specifying a delimiter

Examples: delimiter = ',' delimiter = '-', delimiter = ';'

Stripping specified characters

Example: astring.strip('\n')

Avoid blank lines: if len(line) == 0:

                                             continue

Splitting on commas

Your task is to extract the dates and the corresponding number of lightning strikes

2014-04-10 :   1 lightning strikes were recorded.

2014-04-21 :   19 lightning strikes were recorded.

                              *

                              *            

                              *

2014-09-03 :   102 lightning strikes were recorded.

See if you can output the data with a more familiar date format:

(Hint: split the date and rearrange the elements)

04 10 2014 : 1 lightning strikes were recorded.

04 21 2014 : 19 lightning strikes were recorded.

Please use the following above code and comments to write this code

File sample :

DAY,CENTERLAT,CENTERLON,FCOUNT
2015-04-10,42.7,-73.8,1
2015-04-21,42.7,-73.8,19
2015-05-10,42.7,-73.8,1
2015-05-27,42.7,-73.8,7
2015-05-30,42.7,-73.8,7
2015-06-09,42.7,-73.8,99
2015-06-12,42.7,-73.8,34
2015-06-13,42.7,-73.8,276
2015-06-23,42.7,-73.8,5
2015-07-19,42.7,-73.8,110
2015-08-03,42.7,-73.8,62
2015-08-04,42.7,-73.8,3
2015-08-11,42.7,-73.8,3
2015-08-15,42.7,-73.8,45
2015-09-03,42.7,-73.8,102

The code needs to be as simple as possible using the above example code as reference. It cannot be code that we havent covered in class. so no import, def load

0 0
Add a comment Improve this question Transcribed image text
Answer #1

hey here is solution to your problem.

#opening csv file
with open("file.txt", "r") as ins:
    # lines array to store all the lines of file
    lines = []
    # now looping through each line
    for line in ins:
       #appending each line to the lines array with removing last char of each line
       #because its a "\n" newline char which isnot needed

        lines.append(line[:-1])

# now looping through each line in lines array to print the output
for i in lines:
  
   # splitting each line by "," delimeter so we get seperated arraylist of elements
   temp=i.split(",")
   #data inside temp ['2015-07-19', '42.7', '-73.8', '110']
   count_of_lightning=temp[3]
   #splitting the date attribute so we can reshuflle date to year month date to month date year format
   temp_date=temp[0].split("-")
   # ['2015', '09', '03'] data inside temp_Date variable
   # set date as "month date year"

   #printing final output
   # month date year lightning count
   print (temp_date[1]+" "+temp_date[2 ]+" "+temp_date[0]+ " : "+count_of_lightning + " lightning strikes were recorded.")

In case of any doubt please comment. Happy Learning :)

Add a comment
Know the answer?
Add Answer to:
Using python beginner code see example code of what to use for this assignment we have...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The code should work exactly the same as given example. The files: ---------------------------------------------------...

    The code should work exactly the same as given example. The files: ---------------------------------------------------------------------------------------------------- -------- FILE NAME ------- album0 ---------- FILE ------- <album> 323 Licensed to Ill Beastie Boys 25.0 </album> <album> 70 Enter the Wu_Tang: 36 Cham... Wu Tang Clan 25.99 </album> turning to Alice, she went on, `What's your name, child?' and there stood the Queen in front of them, with her arms folded, <album> 115 Daydream Nation Sonic Youth 5.0 </album> <album> 414 52nd Street Billy Joel 25.75...

  • Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART...

    Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{    int day;    int month;    int year; }; /** This structure is to store the size of the box and it...

  • C++ Need help with this code. Can't use "using namespace std;" Control break report Objectives Read...

    C++ Need help with this code. Can't use "using namespace std;" Control break report Objectives Read data from a text file Write data to a text file Correctly end a file input loop when end of file is reached Process control breaks correctly Calculate sums for grouping of input data Implement an algorithm Format output data on a report neatly Test and debug a program Overview This assignment involves the creation of a level break report. The data file provided...

  • Python program This assignment requires you to write a single large program. I have broken it...

    Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT