Feb-05-2021, 10:26 PM
Hello,
I am having problems changing the following code including a for loop (it is running 1,5 hours by now with no solution yet) into a numpy function. Can someone help me? I could not solve it.
The issue is, that I have double Nodes with different values for tension and I need to average the tension for each node, to have an array or DataFrame just including each Node once.
'Node' values are some integers.
'Spannung' values are floats (tension values belonging to Nodes, which I want to average for same Nodes)
Thank you very much,
ToffiFaye
I am having problems changing the following code including a for loop (it is running 1,5 hours by now with no solution yet) into a numpy function. Can someone help me? I could not solve it.
The issue is, that I have double Nodes with different values for tension and I need to average the tension for each node, to have an array or DataFrame just including each Node once.
'Node' values are some integers.
'Spannung' values are floats (tension values belonging to Nodes, which I want to average for same Nodes)
# next two lines are not the problem, just to understand my script maybe df = pd.DataFrame({'Node': array[:, 0], 'Spannung': array[:, 1]}) df = df.sort_values(by=['Node']) # last node (integer) last_node = df["Node"].iloc[-1] # creating empty DataFrame df2 = pd.DataFrame({'Node':[], 'Spannung':[]}) # iterating over each Node in order to fill df2 with each node and its averaged tansion value for i in range(1, last_node): meanvalue = df[df['Node'] == i].mean() df2.append(pd.DataFrame({'Node':[i], 'Spannung':[meanvalue.at['Spannung']]}))I would be so happy if someone could help me!
Thank you very much,
ToffiFaye