Yes, you are correct, it will be an issue, lets modify the code a bit to write the updated master file to a different folder. This way one can run the script any number of time, however eod they need to put both master & eod.txt file in the same folder first and then copy the updated master file to original folder.
1. Add the following function into the cell with other functions:
def update_eod(masterfile,eodfile):
master = pd.read_csv(masterfile, index_col=[0])
eod = pd.read_csv(eodfile, header=None,index_col=[0],usecols=[0,5])
df = master.append(eod.T).dropna(axis=1).reset_index(drop=True)
df.to_csv('C://master/stockdata.csv')
return
2. Add a new cell after after the cell which reads the master file and add the following python statement
update_eod('C://master/stockdata.csv','C://master/eod.txt')
View attachment 27047
How it works:
1. Every day download the EOD NSE bhavcopy text file and rename it as eod.txt, place it in a folder named "master" along with the old master file.
2. Then just run the cell with the function update_eod to update the master file and then comment this statement with # so that it is not run next time. Remove the # only when you need to update the master file.
3. Once the master file is updated copy the file to the folder used as earlier.
View attachment 27048