In: Computer Science
I want to create a seating chart that I can assign an 'X' to if a seat is purchased. I want to use a numpy array, but am having trouble figuring out how to write it the way I want it. I want it 4 X 15, but with string values instead of all the same value or a range. i would like this. can I do it with numpy? also I want the columns lined up when i do a test print, or write to a text file if possible.
['A1', 'B1','C1','D1' 'A2', 'B2','C2','D2' 'A3', 'B3','C3','D3' 'A4', 'B4','C4','D4' 'A5', 'B5','C5','D5' 'A6', 'B6','C6','D6' 'A7', 'B7','C7','D7' 'A8', 'B8','C8','D8' 'A9', 'B9','C9','D9' 'A10', 'B10','C10','D10' 'A11', 'B11','C11','D11' 'A12', 'B12','C12','D12' 'A13', 'B13','C13','D13' 'A14', 'B14','C14','D14' 'A15', 'B15','C15','D15']
As the data you have provided don't have comma or a bracket after the fourth element. so you first have to make a list of 60 elements then can do this way code is provides.
import numpy as np
l=[['A1', 'B1','C1','D1'],
['A2', 'B2','C2','D2'],
['A3', 'B3','C3','D3'],
['A4', 'B4','C4','D4'],
['A5', 'B5','C5','D5'],
['A6', 'B6','C6','D6'],
['A7', 'B7','C7','D7'],
['A8', 'B8','C8','D8'],
['A9', 'B9','C9','D9'],
['A10', 'B10','C10','D10'],
['A11', 'B11','C11','D11'],
['A12', 'B12','C12','D12'],
['A13', 'B13','C13','D13'],
['A14', 'B14','C14','D14'],
['A15', 'B15','C15','D15']]
ch = np.chararray(4,15)
ch=l
print(l)
Output:-
[['A1', 'B1', 'C1', 'D1'], ['A2', 'B2', 'C2', 'D2'], ['A3', 'B3', 'C3', 'D3'], ['A4', 'B4', 'C4', 'D4'], ['A5', 'B5', 'C5', 'D5'], ['A6', 'B6', 'C6', 'D6'], ['A7', 'B7', 'C7', 'D7'], ['A8', 'B8', 'C8', 'D8'], ['A9', 'B9', 'C9', 'D9'], ['A10', 'B10', 'C10', 'D10'], ['A11', 'B11', 'C11', 'D11'], ['A12', 'B12', 'C12', 'D12'], ['A13', 'B13', 'C13', 'D13'], ['A14', 'B14', 'C14', 'D14'], ['A15', 'B15', 'C15', 'D15']]
You can do it using dataframe and can save it to a csv file. I am adding the code for the same. It will store the data in excel file which will show ith row for the corresponding seating plan.
import numpy as np
import pandas as pd
l=[['A1', 'B1','C1','D1'],
['A2', 'B2','C2','D2'],
['A3', 'B3','C3','D3'],
['A4', 'B4','C4','D4'],
['A5', 'B5','C5','D5'],
['A6', 'B6','C6','D6'],
['A7', 'B7','C7','D7'],
['A8', 'B8','C8','D8'],
['A9', 'B9','C9','D9'],
['A10', 'B10','C10','D10'],
['A11', 'B11','C11','D11'],
['A12', 'B12','C12','D12'],
['A13', 'B13','C13','D13'],
['A14', 'B14','C14','D14'],
['A15', 'B15','C15','D15']]
charar = np.chararray(4,15)
charar=l
print(l)
X=pd.DataFrame(data=l)
X.to_csv(<filename>,index=False)