-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonthly_update.py
36 lines (34 loc) · 1.31 KB
/
monthly_update.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pandas as pd
data = pd.read_csv('nov_jan_positions.csv', index_col=0)
names = set(data['trader'].tolist())
new_data = pd.DataFrame()
ids = []
for username in names:
positions_db = pd.read_csv('nov_jan_positions.csv', index_col=0)
user_positions = positions_db[positions_db['trader'] == username]
descriptions = []
for index, row in user_positions.iterrows():
descriptions.append(row['description'])
descriptions = list(set(descriptions))
open_descriptions = []
for description in descriptions:
same_trades = user_positions[user_positions['description'] == description]
qty = 0
for index, pos in same_trades.iterrows():
qty += pos['quantity']
if qty > 0 or qty < 0:
ids.append(pos['id'])
open_descriptions.append((qty, description))
print(data)
def check_id(row):
if row in ids:
return True
return False
data['newcol'] = data['id'].apply(check_id)
new_data = data[data['newcol']]
new_data['nextcol'] = new_data['description'].apply(lambda x: 'Mar' in x or 'Apr' in x or 'May' in x or 'Jun' in x or 'Jul' in x)
new_data = new_data[new_data['nextcol']]
new_data['time'] = "2021-02-01 01:59:10"
new_data.drop('newcol', axis=1, inplace=True)
new_data.drop('nextcol', axis=1, inplace=True)
new_data.to_csv('extranew.csv')