Question: import pandas as pd # load the target.csv file tgt = pd . read _ csv ( target . csv ) # subset

import pandas as pd
# load the target.csv file
tgt = pd.read_csv("target.csv")
# subset the last 19 days of the dataframe
tgt_march = tgt[-19:]
# subset tgt_march and create a data frame that contains the columns: Date and Volume
tgt_vol = tgt_march[["Date","Volume"]]
# subset tgt_march and create a data frame that contains the columns: Date and Closing
tgt_close = tgt_march[["Date","Close"]]
day = int(input())-1
# subset the specific row of tgt_vol for the given day
volume_row = tgt_vol[pd.to_datetime(tgt_vol['Date']).dt.strftime('%d')== str(day)]
volume = volume_row.iloc[0][1] # gets the volume for the given day
# subset the specific row of tgt_close for the given day
close_row = tgt_close[pd.to_datetime(tgt_close['Date']).dt.strftime('%d')== str(day)]
close = close_row.iloc[0][1] # gets the closing stock price for the given day
date = tgt_march[pd.to_datetime(tgt_march['Date']).dt.strftime('%d')== str(day)].iloc[0][0] # gets the date
print("The volume of TGT on", str(date),"is", str(int(volume))+".")
print("The closing stock price of TGT on", str(date),"is $", str(int(close))+".")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!