You didn’t mention where your data comes from or where it’s going, Sahar, but if you’re looking for a simple approach, reading and reshaping is very doable in native Python without even loading any functions from the Standard Library (stdlib). Note that this will be slower than numpy, for example, but it’s a good way to learn basic python before learning about extended library functions.
- Save the spreadsheet as a csv file
- or put the data directly into a csv file instead of an Excel file.
- Read the rows into a list and strip LF characters.
- Break the list into groups with a slicing window.
raw_list = open("SaharDataIN.csv",'r').read().split()
chunk_size = 10
grouped_list1 = [raw_list[pos:pos + chunk_size] for pos in range(0,len(raw_list), chunk_size)]
#NOTE: the line above is longer than the PEP8 recommendation.
#a narrower version of the 'grouped_list1' list comprehension:
grouped_list2 = 
for pos in range(0,len(raw_list), chunk_size):
grouped_list2.append(raw_list[pos:pos + chunk_size])
And to write the CSV file:
cooked_list = open("SaharDataOUT.csv", 'w')
for row in grouped_list1:
for item in row:
The CSV file will have the following data:
#Excel will ignore the commas at the end of each line.