I want to save the data in a csv file in a specific format but I am getting an error. The desired output is attached.
import numpy as np
import csv
N=2
Pe = np.array([[[128.22918457, 168.52413295, 209.72343319],
[129.01598287, 179.03716051, 150.68633749],
[131.00688309, 187.42601593, 193.68172751]],
[[ 64.11459228, 84.26206648, 104.86171659],
[ 64.50799144, 89.51858026, 75.34316875],
[ 65.50344155, 93.71300796, 96.84086375]]])
with open('Test123.csv', 'w') as f:
for x in range(0,N):
print([Pe[x]])
writer = csv.writer(f)
# write the data
writer.writerows(zip(x,Pe[x]))
The error is
TypeError: 'int' object is not iterable
The desired output is

zip(x,Pe[x])sincexis an int it cannot be iterated over. Can you use pandas here?