Devashish18/bulk_deal_data_processor
0
1# Importing necessary libraries2import pandas as pd3import numpy as np4import streamlit as st5 6# Function to calculate traded quantity7def calculate(quantity_traded):8 return int(quantity_traded.replace(',', ''))9 10# Function to process the CSV and return a sorted DataFrame11def process_csv(dataframe):12 name = {}13 14 for i, row in dataframe.iterrows():15 security_name = row['Security Name ']16 quantity_traded = row['Quantity Traded ']17 buy_sell = row['Buy / Sell ']18 19 if security_name not in name:20 name[security_name] = 021 22 if buy_sell == 'BUY':23 name[security_name] += calculate(quantity_traded)24 else:25 name[security_name] -= calculate(quantity_traded)26 27 x = pd.DataFrame(name.items(), columns=['Security Name', 'Quantity Traded'])28 29 # Sort the DataFrame by 'Quantity Traded' in descending order30 x = x.sort_values(by='Quantity Traded', ascending=False)31 32 return x33 34# Streamlit app title35st.title("Bulk Data Processor")36 37# File uploader widget for the CSV file38uploaded_file = st.file_uploader("Choose a CSV file", type="csv")39 40# If a file is uploaded, process it41if uploaded_file is not None:42 # Read the CSV file43 df = pd.read_csv(uploaded_file)44 45 # Display the original DataFrame46 st.write("Original DataFrame:")47 st.dataframe(df)48 49 # Process the CSV50 processed_df = process_csv(df)51 52 # Display the processed DataFrame53 st.write("Processed DataFrame:")54 st.dataframe(processed_df)55 56 # Download the processed CSV file57 csv = processed_df.to_csv(index=False).encode('utf-8')58 st.download_button(label="Download Processed CSV", data=csv, file_name="bulkdata_revised.csv", mime='text/csv')59 