2

How can I store data with spacial characters in the index (e.g: äüö) into a HDF file.

Create a DataFrame:

    import pandas as pd
    import numpy as np

    df = pd.DataFrame(np.random.randn(8, 4),
                      columns=['A','B','C','D'],
                      index=["a", "ä", "b", "c", "d", "e", "f", "g"])

    df.to_hdf("test.h5", "data")

Read the data from the hdf file:

    store = pd.HDFStore("test.h5")

Missing index:

    In [17]: store.data
    Out[17]: 
              A         B         C         D
    a  0.859861 -1.017473 -0.095029  0.220382
       0.472394  0.658839  0.494681 -0.350250
    b  1.180679  0.513142  1.286615  0.807974
    c -0.382927  1.983893  0.553454 -0.246470
    d -1.738026  2.050707  0.820716 -0.564973
    e -0.104748  0.926204 -0.543239 -0.632866
    f  0.886118  0.948541  1.759265 -0.937207
    g -1.670633  0.069873  0.037105 -0.809620
omun
  • 113
  • 1
  • 7
  • What is your python version, and what is the result you get from `sys.getdefaultencoding()`? – TheBlackCat Apr 14 '15 at 10:00
  • Also what are your pandas and pytables versions? Your code works fine for me with python 2.7 (pandas 15.2, pytables 3.1.1) but silently fails for python 3.4 with an identical output to yours . It's possible that there is a bug in pandas there. – rth Apr 14 '15 at 21:23
  • This is related to the following issues https://github.com/pydata/pandas/issues/7244 and https://github.com/pydata/pandas/issues/7605 Updating to pandas 16.0 might help. – rth Apr 14 '15 at 21:32
  • 1
    I am using pandas 0.16.0 and also have the problem. – TheBlackCat Apr 15 '15 at 10:02
  • `sys.getdefaultencoding()` --> **utf-8** I'm usig python version **3.4.3** and pandas version **0.15.0** – omun Apr 15 '15 at 10:05
  • I also have `utf-8` on python 3.4.1 and pandas 0.16.0, and can reproduce the problem. – TheBlackCat Apr 15 '15 at 12:38

0 Answers0