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:
cooked_list.writelines(item+',')
cooked_list.write("\n")
cooked_list.close()
The CSV file will have the following data:
1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,
#Excel will ignore the commas at the end of each line.