Can Hail convert mt.show() output to dataframe

I just wonder if Hail can export mt.show() output to dataframe?
I only found hail table can do ht.to_pandas, not for matrix table.

Please advise.

Thanks

2 Likes

You have to go through make_table which converts from the compact Matrix Table to a “splatted” Table representation. This representation is not as efficient as the Matrix Table one, but it can be helpful if you’ve already filtered to a small amount of data:

mt = hl.balding_nichols_model(1, 100, 100)
mt = mt.head(10, 10)
# make_table only works if your column key is a string
mt = mt.key_cols_by(sample_idx = hl.str(mt.sample_idx))
mt.make_table().to_pandas()
  locus alleles  ancestral_af                     af 0.GT 1.GT 2.GT 3.GT 4.GT 5.GT 6.GT 7.GT 8.GT 9.GT
0   1:1  [A, C]       0.56562   [0.5065377367423387]  0/1  0/0  0/1  1/1  0/0  0/0  0/1  0/0  0/1  0/1
1   1:2  [A, C]      0.365205   [0.6258964574553554]  0/1  0/0  0/1  0/1  1/1  1/1  0/1  0/1  0/0  0/1
2   1:3  [A, C]      0.264213  [0.33177520558402107]  0/1  0/0  0/1  0/0  1/1  0/0  0/1  1/1  1/1  0/0
3   1:4  [A, C]      0.657153   [0.6621287358731078]  1/1  1/1  1/1  0/1  0/1  0/1  0/1  0/1  0/0  1/1
4   1:5  [A, C]      0.587436   [0.6571430380430893]  1/1  1/1  0/1  0/1  1/1  0/0  0/0  0/1  1/1  0/1
5   1:6  [A, C]      0.612322  [0.45384524206238214]  0/1  0/0  0/1  0/0  0/0  1/1  0/1  0/1  0/0  0/1
6   1:7  [A, C]      0.544037   [0.5309164404722725]  0/0  0/1  0/0  0/0  0/1  0/1  1/1  0/1  0/1  1/1
7   1:8  [A, C]       0.32731  [0.36741746942847303]  0/0  0/0  0/0  0/1  0/1  0/0  0/1  0/1  1/1  0/0
8   1:9  [A, C]        0.1855   [0.3122103370259781]  0/0  0/1  0/1  1/1  0/1  0/1  0/1  0/0  0/0  0/1
9  1:10  [A, C]      0.644705   [0.5776664019578889]  0/1  0/0  0/1  1/1  1/1  0/1  0/1  1/1  0/1  1/1

I recommend saving your dataset to a file, reading the file back in, and then using make_table().to_pandas().

Thank you so much, I have used the seond option. :slight_smile: