Get Started

Extracting data from your HDF5 file

In this exercise, you'll extract some of the LIGO experiment's actual data from the HDF5 file and you'll visualize it.

To do so, you'll need to first explore the HDF5 group 'strain'.

This is a part of the course

“Introduction to Importing Data in Python”

View Course

Exercise instructions

  • Assign the HDF5 group data['strain'] to group.
  • In the for loop, print out the keys of the HDF5 group in group.
  • Assign the time series data data['strain']['Strain'] to a NumPy array called strain.
  • Set num_samples equal to 10000, the number of time points we wish to sample.
  • Execute the rest of the code to produce a plot of the time series data in LIGO_data.hdf5.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Get the HDF5 group: group


# Check out keys of group
for key in ____:
    print(____)

# Set variable equal to time series data: strain


# Set number of time points to sample: num_samples


# Set time vector
time = np.arange(0, 1, 1/num_samples)

# Plot data
plt.plot(time, strain[:num_samples])
plt.xlabel('GPS Time (s)')
plt.ylabel('strain')
plt.show()

This exercise is part of the course

Introduction to Importing Data in Python

BeginnerSkill Level
4.7+
88 reviews

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 file
Exercise 16: Importing MATLAB filesExercise 17: Loading .mat filesExercise 18: The structure of .mat in Python

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free