Created
June 30, 2019 01:14
-
-
Save bharddwaj/083cce08f16cbbc22c3da123f5801278 to your computer and use it in GitHub Desktop.
Calculates volume per trading day in the csv file and graphs it. Also writes down the exact volumes at each day to a txt file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import csv | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import math | |
data = pd.read_csv("CL_June_2019.csv") | |
#new_data = data[59528000:59800000] | |
#print(new_data) | |
#new_data.to_csv("new_file.csv") | |
count = 0 | |
volume = [] | |
dict = {} | |
volume.append(data['Volume']) | |
volume.append(data['Date-Time']) | |
#print(volume[1][0][0:10]) | |
for i in range(len(volume[0])): | |
count += 1 | |
vol = volume[0][i] | |
date = volume[1][i][5:10] #prints the whole date excluding the time | |
if not math.isnan(vol): | |
if date in dict: | |
dict[date] += vol | |
else: | |
dict[date] = vol | |
print(count) | |
#k = [keys for keys in dict] | |
#v = [dict[keys] for keys in dict] | |
keys = [] | |
vals = [] | |
for k,v in dict.items(): | |
keys.append(k) | |
vals.append(v) | |
sns.barplot(x = keys,y =vals ) | |
plt.xlabel("Date") | |
plt.ylabel('Volume') | |
plt.title("Volume") | |
plt.savefig("figuresomething2.png") | |
with open('volume2.txt','w') as file: | |
for k,v in dict.items(): | |
#file.write(f"{k}: {int(v)} \n") | |
file.write(str(k) + ": " + str(int(v)) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment