Skip to content

Instantly share code, notes, and snippets.

@cameronShadmehry
Created June 12, 2021 04:40
Show Gist options
  • Save cameronShadmehry/57d791ea60284748c6e6fe3d3448e8b7 to your computer and use it in GitHub Desktop.
Save cameronShadmehry/57d791ea60284748c6e6fe3d3448e8b7 to your computer and use it in GitHub Desktop.
# Convert the data into a dataframe.
df = pd.DataFrame(data=test['data'])
# Derived attributes from the data.
df['dollarAmount'] = df['change']*df['transactionPrice']
df['insiderPortfolioChange'] = df['change']/(df['share'] - df['change'])
# print(type(df['transactionPrice'][0]))
conditions = [
(df['change'] >= 0) & (df['transactionPrice'] > 0),
(df['change'] <= 0) & (df['transactionPrice'] > 0),
(df['transactionPrice'] == 0)
]
values = ['Buy', 'Sale', 'Gift']
df['buyOrSale'] = np.select(conditions, values)
print(df)
df.to_csv('YOUR PATH\\'+stock+'.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment