Using h5py to import HDF5 files
The file 'LIGO_data.hdf5'
is already in your working directory.
In this exercise, you'll import it using the h5py
library.
You'll also print out its datatype to confirm you have imported
it correctly. You'll then study the structure of the file in order
to see precisely what HDF groups it contains.
You can find the LIGO data plus loads of documentation and tutorials here. There is also a great tutorial on Signal Processing with the data here.
This is a part of the course
“Introduction to Importing Data in Python”
Exercise instructions
- Import the package
h5py
. - Assign the name of the file to the variable
file
. - Load the file as read only into the variable
data
. - Print the datatype of
data
. - Print the names of the groups in the HDF5 file
'LIGO_data.hdf5'
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import packages
import numpy as np
import ____
# Assign filename: file
# Load file: data
data = h5py.File(____, ____)
# Print the datatype of the loaded file
# Print the keys of the file
for key in ____:
print(____)
This exercise is part of the course
Introduction to Importing Data in Python
Learn to import data into Python from various sources, such as Excel, SQL, SAS and right from the web.
You've learned how to import flat files, but there are many other file types you will potentially have to work with as a data scientist. In this chapter, you'll learn how to import data into Python from a wide array of important file types. These include pickled files, Excel spreadsheets, SAS and Stata files, HDF5 files, a file type for storing large quantities of numerical data, and MATLAB files.
Exercise 1: Introduction to other file typesExercise 2: Not so flat any moreExercise 3: Loading a pickled fileExercise 4: Listing sheets in Excel filesExercise 5: Importing sheets from Excel filesExercise 6: Customizing your spreadsheet importExercise 7: Importing SAS/Stata files using pandasExercise 8: How to import SAS7BDATExercise 9: Importing SAS filesExercise 10: Using read_stata to import Stata filesExercise 11: Importing Stata filesExercise 12: Importing HDF5 filesExercise 13: Using File to import HDF5 filesExercise 14: Using h5py to import HDF5 filesExercise 15: Extracting data from your HDF5 fileExercise 16: Importing MATLAB filesExercise 17: Loading .mat filesExercise 18: The structure of .mat in PythonWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.