0

I have below data. These are satellite number ,its state and value. Here Value of status 'B' is changing either 0 or some value. Value of status 'A' is always 0. Sat with status A and Val=0 for corresponding status 'B'is not acceptable and not counted.

My aim is to iterate through each row and find correct Satellite present at each row. If any row is all A or B=0 that row is not counted.

So my desire output is : a=3,1,1,1 Count=4 ,Row 4 is not counted

sv-01   sv-02  SV-03  state-01 state-02 state-03    val-01   val-02  val-03
 7        12     8         B          B         B     .23     0.34    1.03
 7        12     8         B          B         A     .35     0       0
 7        12     8         B          A         A     1.45    0       0
 7        12     8         A          A         A      0      0       0
 7        12     8         A          B         B      0      0     3.21

# My python implementation is

  mask = read_data.filter(like='state').eq('A')
  result_count_Nj1 = mask.sum(axis=1).rsub(3)

# I have tried

mask = read_data.filter(like='state').eq('A')  and read_data.filter(like='state').eq('B'!=0)

# But it shows error. Please suggest where I am making mistake

Thanks

Poka
  • 387
  • 1
  • 12
  • I'm not sure I understand what you mean by Value, State, and Status; that said, would this framework be helpful? `df2 = df.drop(df[(df['state-01'] == 'A') & (df['val-02'] == 0)].index)` From: https://stackoverflow.com/questions/13851535/how-to-delete-rows-from-a-pandas-dataframe-based-on-a-conditional-expression – Evan Dec 04 '17 at 05:20
  • @ Evan.Yeah it would be state. Value is nothing but val-01,val-02,val-03. Then how would I count number of satellite at each row and number of count – Poka Dec 04 '17 at 05:23

1 Answers1

1

I believe you need:

#check B values
maskB = read_data.filter(like='state') == 'B'
print (maskB)
   state-01  state-02  state-03
0      True      True      True
1      True      True     False
2      True     False     False
3     False     False     False
4     False      True      True

#check not 0 values for B values only
mask0 = read_data.filter(like='val').where(maskB.values, 0) != 0
print (mask0)
   val-01  val-02  val-03
0    True    True    True
1    True   False   False
2    True   False   False
3   False   False   False
4   False   False    True

a = mask0.sum(1)
print (a)
0    3
1    1
2    1
3    0
4    1
dtype: int64

b = mask0.any(1).sum()
print (b)
4
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252