-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parsing transaction data to dataframe
- Loading branch information
Showing
3 changed files
with
42 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
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() |