I am doing an analysis of food expenditures by 5 different members belonging to 5 different age group. I want to create a file in .npz format, which should have two variables, viz., 'age' and 'person'. I am trying to get an array containing a list of arrays.
I created a list of 5 members 'person' and a list of 5 corresponding age group as 'age'. However, after accessing the created .npz file, I am getting a combined array of size (5,7).
person1 = np.array([(1, 2, 3, 4),
(4, 5, 6, 5),
(7, 8, 9, 6),
(9, 6, 5, 4),
(6, 5, 4, 3),
(6, 5, 4, 3),
(4, 3, 5, 7)],
dtype=[('BF', '<f8'), ('Lunch', '<f8'), ('Snacks', '<f8'), ('Dinner', '<f8')])
person2 = person1
person3 = person1
person4 = person1
person5 = person1
person = [person1, person2, person3, person4, person5]
age = [10, 20, 30, 40, 50]
np.savez('test.npz', age=age, person=person)
with np.load('test.npz', allow_pickle=False) as data:
list_person = data['person']
age_group = data['age']
# df = pd.DataFrame(list_person)
# df.to_excel('test.xlsx', index=True)
I am expecting 'list_person' as an array of size (5,). Each element of which should have an array of shape (7,4). So that while exporting in excel I get (5,1) data.