Skip to content

Commit

Permalink
Add parsing transaction data to dataframe
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmcd committed Oct 8, 2019
1 parent bf079fd commit c5e3493
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jupyter = "*"
py-etherscan-api = "*"
web3 = "*"
eth-abi = "*"
python-dotenv = "*"

[requires]
python_version = "3.7"
27 changes: 17 additions & 10 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions infmon/pd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pandas as pd


def create_dataframe(tx_interface, tx_list, delete_cols=None, keep_cols=None):
"""Turn transaction data into pandas dataframe
:param tx_interface: event interface returned by io.get_event_interface
:param tx_list: list of transactions returned by io.get_contract_events
:param delete_cols: transaction metadata to delete, default ['data' (after parsing), 'logIndex']
:param keep_cols: transaction metadata to keep, default ['blockNumber', 'blockHash', 'transactionHash']
:return: dataframe of transaction data and metadata
"""
if delete_cols is None:
delete_cols = ['data', 'logIndex']
if keep_cols is None:
keep_cols = ['blockNumber', 'blockHash', 'transactionHash']
df_temp = pd.DataFrame(tx_list)

df = df_temp.join(
pd.DataFrame([tx_interface['decode'](t) for t in tx_list])
).drop(
columns=delete_cols
).loc[:, keep_cols + tx_interface['indexed_names'] + tx_interface['names']]
return df.copy()

0 comments on commit c5e3493

Please sign in to comment.