How to export dataframe from google collaboration as .h5?

Viewed 22

I'm trying to export dataframe in .h5 format from Google Colab, the package I'm using to do downstream analysis reads in that format so would like it to export in that specific file format.

I know to export it into csv file format you do:

from google.colab import drive
drive.mount('drive')
adata.to_csv('adata.csv')
!cp df.csv "drive/My Drive/"

but I am not sure what is the right command is to execute export into .h5 format. Any help is greatly appreciated! Thank you.

1 Answers

You need to use to_hdf method:

from google.colab import drive
drive.mount('drive')
adata.to_hdf('adata.h5', key='adata')
!cp adata.h5 "drive/My Drive/"
Related