Hi I am adding specific cells in a row. In some cases they are a continuous range but never the entire row! This is why I'm wondering if there is a better way of doing this than:
import pandas as pd, numpy as np
mininmal_array = np.random.rand(3,3)
min_df = pd.DataFrame(mininmal_array, columns=['H', 'E', 'C'], index=['H', 'E', 'C'])
display(min_df)
# Summing only field E and C from row H:
sum_EC = min_df['E']['H']+min_df['C']['H']
print(sum_EC)
Is there a more elegant way of doing this? I mean whenever the fields are adjacent. The important point is that I do NOT want to sum the entire row.
What would be the way of doing this with a colum? E.g In column 'E' Summing exclusively filed EE and EC:
sum_col = min_df['E']['E']+min_df['E']['C']
print(sum_col)
# 0.937706262999336
I am also wondering if there is a way to sum all cells that do not have matching index and column. E.g. sum all cells were column!=['E'] AND index!=['E'].
Thanks for your constructive answers in advance.