Skip to content

Commit

Permalink
Updating to consume bhavcopy file
Browse files Browse the repository at this point in the history
Amending code to consume bhavcopy file instead of full_bhavcopy which is not available on NSE anymore.
  • Loading branch information
yash12392 authored Mar 6, 2021
1 parent 2a5dfbb commit 98f34a7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions codes_on_blog/bhavcopy_data_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
csv_file_name = csv_file.split('\\')[7]
print('Processing File : {}'.format(csv_file_name))
df.columns = df.columns.str.replace(' ', '')
df['DATE1'] = pd.to_datetime(df['DATE1'])
df.set_index(['DATE1'], inplace=True)
df.drop(['LAST_PRICE', 'PREV_CLOSE'], axis=1, inplace=True)

df = df.apply(lambda x: x.str.strip() if x.dtype == 'object' else x)

new_df = df[df['SERIES'].isin(['EQ', 'BE', 'SM'])]
df['TIMESTAMP'] = pd.to_datetime(df['TIMESTAMP'])
df.set_index(['TIMESTAMP'], inplace=True)

if 'Unnamed:13' in df.columns:
df.drop(['Unnamed:13'], axis=1, inplace=True)

df_trim = df.apply(lambda x: x.str.strip() if x.dtype == 'object' else x)

new_df = df_trim[df_trim['SERIES'].isin(['EQ', 'BE', 'SM'])]
final_df = final_df.append(new_df)

final_df.sort_index(inplace=True) #to sort by dates
Expand Down

0 comments on commit 98f34a7

Please sign in to comment.