'Adding info to specific cells on Excel using Python
I'm working with 60 different datasets, each of them with a ton of data in them. I'm trying to build a loop to go through each of the datasets (they are text files), take the information that I want and put it in the row and column corresponding to the specific dataset, on the Excel file.
Illustrating with an example:
Imagine that in the first iteration of the loop, I start with data/processed/run_0.dat (line 2). Inside of the loop I "enter" this data-set, take the information out regarding rpm and TSR (last 2 columns) and I want to put that information in line 2 and columns Q and R.
The problem I am facing is that when I enter the 2nd iteration of the loop (for data/processed/run_1.dat ) and I try to insert the information in the right place (line 3, columns Q and R), it replaces the information from the previous iteration and I get the same value in line 2 and 3, instead of just adding a value to line 3.
This is the code I am trying to work with:
recap['Cxmin_rose'] = 0
recap['Cymmax_rose'] = 0
recap['Cxmin_houle'] = 0
recap['Cxmax_houle'] = 0
list = [datar3_w_reg, datar7_w_reg, datar3_w_irreg, datar7_w_irreg, datar3_sh, datar7_sh, datar3_w_reg1, datar7_w_reg1, datar3_w_reg1_5, datar7_w_reg1_5, datar3_w_reg2, datar7_w_reg2]
DS = []
error_DS_list = []
### analyse data
for j in list:
for i in range(len(j)):
try:
run_path = j.iloc[i]
name = run_path.processed_file
name1 = name.split('/')
name_final = name1[2]
DS.append(name_final)
print(name_final)
if DS.count(name_final) == 1:
time, angle, couple, rpm, Fx, Fy, Fz, Mx, My , Mz , U , V, H = load_data(path_data + run_path.processed_file)
dt = time[1] - time[0]
minrose, maxrose, minwave, maxwave = minmaxrose_minmmaxH(Fx, angle, H)
recap['Cxmin_rose'] = minrose
recap['Cymmax_rose'] = maxrose
recap['Cxmin_houle'] = minwave
recap['Cxmax_houle'] = maxwave
recap.to_excel(os.path.join(path_data,'recap_essai - JRS.xlsx'))
print('')
else:
continue
minmaxrose_minmmaxH
is a little function defined by me and recap is the variable to which I attributed the Excel file ( recap = pd.read_excel(os.path.join(path_data,'recap_essai - JRS.xlsx'))
).
How can I specify the exact place (cell) in Excel that I want to put the data into?
Thank you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|