Description
You will modify a csv file containing stock information. The file ‘tickerInfo.csv’ can be found on
BlackBoard. It contains the date, closing price, high price, low price, opening price, and volume for the
first four months of 2017. You need to create a new file that contains the date, closing price, opening
price, amount the price changed, and a flag indicating if the stock went up or not.
tickerInfo.csv might become corrupted if you open it in Excel. If you would like to view the file before
processing it, you should open it in a text editor like Notepad or Notepad++. If prompted, do not save
the file after opening it. If your file becomes corrupted, or if you are getting an unexplained error, try
replacing the file on your machine with a fresh version downloaded from BlackBoard.
Your code will:
1. Include your first name, last name, and Homework 6 on line 1, like
#Michael Deamer Homework 6
2. On lines 2 and 3, create the string variables you will use to open the source and destination
files. Use the variable names originalFileName and modifiedFileName, like
originalFileName = ‘C:/Users/michael.deamer/Desktop/Python IO/tickerInfo.csv’
modifiedFileName = ‘C:/Users/michael.deamer/Desktop/Python IO/tickerInfoWithDelta.csv’
Note:
While developing your script, change these strings to reflect where the
tickerInfo.csv file can be found on your machine.
3. Open the tickerInfo and destination files;
4. Read the information from tickerInfo;
5. Calculate two new columns:
a. Delta: indicates how much the stock changed during the day (close – open); and
b. Direction: indicates if the stock went up or not. If the stock went up, the value in this
column should be 1, else 0;
6. Write five columns to the destination file:
a. Date
b. Close
c. Open
d. Delta (from Step 5)
e. Direction (from Step 5)
Note:
The destination file should not include the High, Low, or Volume columns form the
source file.
7. The resulting file should have column headers: Date, Close, Open, Delta, and Direction;
After you have completed the assignment and before you submit your code to BlackBoard, please
change lines 2 and 3 back to how they appear below:
originalFileName = ‘C:/Users/michael.deamer/Desktop/Python IO/tickerInfo.csv’
modifiedFileName = ‘C:/Users/michael.deamer/Desktop/Python IO/tickerInfoWithDelta.csv’
Note:
These paths reflect where those files will be found on the instructor’s machine during
grading.
Only submit your py file – you don’t need to attach any csv files.
Extra challenge (Optional):
1. Can you show trending? For example, can you create a new column that indicates that a stock
has gone up four days in a row or more?
Application examples:
tickerInfo.csv initially looks like this:
Date Close High Low Open Volume
1/3/2017 4 4.11 3.9 4.1 3497700
1/4/2017 4.09 4.25 3.97 4 7940100
1/5/2017 3.8 4.18 3.71 4.12 7732300
1/6/2017 3.6 3.81 3.46 3.8 7743200
1/9/2017 3.67 4.86 3.62 4.8 34775900
…etc
tickerInfoWithDelta.csv should look like this:
Date Close delta direction
1/3/2017 4 -0.1 0
1/4/2017 4.09 0.09 1
1/5/2017 3.8 -0.32 0
1/6/2017 3.6
-0.2
0
1/9/2017 3.67
-1.13
0
…etc