[ Memo ] Connect a List of Lists and Seperate Them

  • Result:
Before After
  • 首先说明:由于数据量原因,下方的操作都避免使用完整循环结构,尽量使用pandas的操作以及列表生成式

  • 首先计算每个transfers中有多少个vout

1
transfers['outcount'] = transfers.vout.apply(len)
  • 根据这个outcount创建一个嵌套列表
1
2
counts = list(transfers.outcount)
ids = [[i]*counts[i] for i in range(len(transfers))]
  • 然后拼接这个嵌套列表
1
idss = [x for j in ids for x in j]
  • 接下来拼接vouts
1
2
vouts = [x for j in list(transfers.vout) for x in j]
vouts = pd.DataFrame(vouts)
  • 最后,将两个拼接后的列表组合:
1
vouts['txid'] = idss