James Li
James Li

Reputation: 1

Missing optional dependency 'tables'. Use pip or conda to install tables

import sys
#import datetime as dt
import numpy as np
import pandas as pd
from pylab import plt
plt.style.use('ggplot')
import matplotlib as mpl

mpl.rcParams['font.family'] = 'serif'

def load_h5(fn):
    h5 = pd.HDFStore(fn, 'r')
    data = h5['data']
    log_returns = h5['log_returns']

    h5.close()
    return data, log_returns


def save_h5(fn, data, log_returns):
    h5 = pd.HDFStore(fn, 'w')
    h5['data'] = data
    h5['log_returns'] = log_returns
    h5.close()

import os
from os.path import isfile, join

fn = join(os.getcwd(), 'stock.h5')
data, log_returns = load_h5(fn)
log_returns.head()

I wanted to read 'stock.h5' file which is place in the same folder and ran the above code. The jupyter notebook gave the error below enter image description here

I tried:

pip install --user tables

conda install --user tables

degrade pytables to 3.5.1

And none of them works

Upvotes: 0

Views: 4266

Answers (2)

LCheng
LCheng

Reputation: 400

I think pd.to_hdf() and pd.read_hdf() could simply realize the saving and loading hdf5 files' requirements without installing the tables package.

Upvotes: 0

Burnt Umber
Burnt Umber

Reputation: 143

I ran into the same thing. The error tells you (unhelpfully) that the missing package is called tables when in fact, it's called pytables. Doing conda install pytables is all I needed to do to be able to read h5 files with pandas.

Upvotes: 4

Related Questions