Python Forum
Automating PyTables Dataset Creation and Append
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automating PyTables Dataset Creation and Append
#1
In my script, I create several datasets manually:

        import tables
        dset1 = f.create_earray(f.root, "dataset1", atom=tables.Float64Atom(), shape=(0, 2))
        dset2 = f.create_earray(f.root, "dataset2", atom=tables.Float64Atom(), shape=(0, 2))
        dset3 = f.create_earray(f.root, "dataset3", atom=tables.Float64Atom(), shape=(0, 2))
        ...
I want to achieve two things:
1) Automate the above statements to execute in a loop fashion and create any desired (N) datasets
2) Then I also use .append method sequentially (as given below) which I also want to automate:

        dset1.append(np_array1) 
        dset2.append(np_array2) 
        dset3.append(np_array3) 
        ...
Will appreciate any assistance?
Reply
#2
Make an array of your arrays, and an array of your datatables.
The code below uses Pandas as I am more familiar, but the concept is the same.
import pandas as pd

array_of_arrays = [[1,2,3]]
array_of_arrays.append([4,5,6])
array_of_arrays.append([7,8,9])

array_of_datasets = list()
nsets = int(input('Enter number of datasets: '))
for i in range(nsets):
    array_of_datasets.append(pd.DataFrame(array_of_arrays[i%3]))

for i in range(nsets):
    print(array_of_datasets[i])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pytables : Printing without special characters Robotguy 0 1,661 Nov-06-2020, 10:55 PM
Last Post: Robotguy
  Automating to generate multiple arrays Robotguy 1 1,780 Nov-05-2020, 08:14 AM
Last Post: Gribouillis
  Reading a table generated using PyTables Robotguy 1 1,500 Sep-18-2020, 03:10 PM
Last Post: Larz60+
  Pytables: Reducing size of an appended Earray Robotguy 0 1,626 Aug-19-2020, 05:35 PM
Last Post: Robotguy
  Using Pytables to Sort Large Arrays? Robotguy 0 1,990 Aug-12-2020, 03:35 PM
Last Post: Robotguy
  Automating to save generated data Robotguy 3 2,226 Aug-12-2020, 03:32 PM
Last Post: Robotguy
  Automating the code using os.walk kiton 20 14,159 Apr-13-2017, 06:15 PM
Last Post: kiton

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020