code: def map_transaction(txn):
      
  
      if isinstance(txn['sid'], dict):
          sid = txn['sid']['sid']
          symbol = txn['sid']['symbol']
      else:
          sid = txn['sid']
          symbol = txn['sid']
  
      return {'sid': sid,
              'symbol': symbol,
              'price': txn['price'],
              'order_id': txn['order_id'],
              'amount': txn['amount'],
              'commission': txn['commission'],
              'dt': txn['dt']}
docs: Maps a single transaction row to a dictionary.
  
      Parameters
      ----------
      txn : pd.DataFrame
          A single transaction object to convert to a dictionary.
  
      Returns
      -------
      dict
          Mapped transaction.