Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming a table in pandas hdfstore

I am using pandas to join several huge csv files using HDFStore. I'm merging all the other tables to a base table, base. Right now I create a new table in the HDFStore for the output of each merge, which I call temp. Then I delete the old base table. Finally, I copy temp to base and start the process over again on the next table I need to join.

This would be much more efficient if I could simply rename temp to base. Is this possible?

like image 500
Luke Avatar asked Apr 01 '14 22:04

Luke


1 Answers

Yes, it is possible. You have to delve into the methods from PyTables, on which HDFStore depends.

Out[20]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/a            frame        (shape->[3,1])

In [21]: store.get_node('a')._f_rename('b')

In [22]: store
Out[22]: 
<class 'pandas.io.pytables.HDFStore'>
File path: test.h5
/b            frame        (shape->[3,1])

The same method works on frame_table appendable nodes.

like image 61
Dan Allan Avatar answered Sep 19 '22 23:09

Dan Allan