Connect transactions to the account network
Python’s read_csv function reads the two CSV data sources into DataFrames
named accounts_df and transactions_df. The source loader also estimates
the time needed to review each transfer from its amount. Account.new(...)
and Transaction.new(...) map the imported records to instances of the
Account and Transaction concepts shown in the Model Explorer.
Transaction.sender(...) and Transaction.receiver(...) define
relationships between each transfer and its sending and receiving
accounts, which the next steps use to trace money moving between accounts.
accounts_df = read_csv(data_dir / "accounts.csv") transactions_df = read_csv(data_dir / "transactions.csv", parse_dates=["step_ts"]) transactions_df["audit_cost"] = np.where( transactions_df["amount"] > large_amount_threshold, large_audit_cost_hours, small_audit_cost_hours, ) train_df = read_csv(data_dir / "train.csv", parse_dates=["step_ts"]) val_df = read_csv(data_dir / "val.csv", parse_dates=["step_ts"]) test_df = read_csv(data_dir / "test.csv", parse_dates=["step_ts"])
model.define(Account.new(model.data(accounts_df).to_schema())) model.define(Transaction.new(model.data(transactions_df).to_schema())) model.define(TrainTable.new(model.data(train_df).to_schema())) model.define(ValTable.new(model.data(val_df).to_schema())) model.define(TestTable.new(model.data(test_df).to_schema()))
model.define(Transaction.sender(Transaction, Account)).where( Transaction.name_orig == Account.account_id ) model.define(Transaction.receiver(Transaction, Account)).where( Transaction.name_dest == Account.account_id ) accounts_df = read_csv(data_dir / "accounts.csv") transactions_df = read_csv(data_dir / "transactions.csv", parse_dates=["step_ts"]) transactions_df["audit_cost"] = np.where( transactions_df["amount"] > large_amount_threshold, large_audit_cost_hours, small_audit_cost_hours, ) train_df = read_csv(data_dir / "train.csv", parse_dates=["step_ts"]) val_df = read_csv(data_dir / "val.csv", parse_dates=["step_ts"]) test_df = read_csv(data_dir / "test.csv", parse_dates=["step_ts"])
model.define(Account.new(model.data(accounts_df).to_schema())) model.define(Transaction.new(model.data(transactions_df).to_schema())) model.define(TrainTable.new(model.data(train_df).to_schema())) model.define(ValTable.new(model.data(val_df).to_schema())) model.define(TestTable.new(model.data(test_df).to_schema()))
model.define(Transaction.sender(Transaction, Account)).where( Transaction.name_orig == Account.account_id ) model.define(Transaction.receiver(Transaction, Account)).where( Transaction.name_dest == Account.account_id )