-3

i hope you can help me. i need to get this result: for item in each row, create Max(In/Out Util)-1Mbr column with result:

df['Max(In/Out Util)-1Mbr'] = [df['Max(In/Out Util)']/100*df['Egress Speed']] / [df['Egress Speed']-(df['Egress Speed']/df['Oper. Member Count'])]*100

Original DataFrame

Site Name           Oper. Member Count  Egress Speed    Max(In/Out Util)
KB201_XXX71_SR7                     2       6000000             11,1527 
KB201_XXX71_SR7                     2           N/A                 N/A 
KN092_XXX71_SR7                     4       4000000             9,60783

FinalDataFrame

Site Name           Oper. Member Count  Egress Speed    Max(In/Out Util)    Max(In/Out Util)-1Mbr
KB201_XXX71_SR7                     2       6000000             11,1527                     22,3
KB201_XXX71_SR7                     2           N/A                 N/A                     N/A
KN092_XXX71_SR7                     4       4000000             9,60783                     12,8
juanpb12
  • 125
  • 1
  • 9

2 Answers2

3

All you need to do is set up the math formula to express the result with the name of the columns:

   df['col4'] = (df['col1']+df['col2'])/df['col3']

EDIT: Newly requested formula:

df['Max(In/Out Util)-1Mbr'] = [df['Max(In/Out Util)']/100*df['Egress Speed']] / [df['Egress Speed']-(df['Egress Speed']/df['Oper. Member Count'])]*100 

EDIT2: Based on the fact your numbers are coded with Latin notation (this is, commas being used to symbolize decimal places) you should start by using:

df = df.apply(lambda x: x.str.replace(',','.'))
df['Max(In/Out Util)-1Mbr'] = df['Max(In/Out Util)-1Mbr'].astype(int)
df['Egress Speed'] = df['Egress Speed'].astype(int)
df['Oper. Member Count'] = df['Oper. Member Count'].astype(int)

And then your proposed formula:

df['Max(In/Out Util)-1Mbr'] = (df['Max(In/Out Util)']*df['Egress Speed']) / (df['Egress Speed'] - df['Egress Speed'] / df['Oper. Member Count'])

Just use the final formula and it should work.

Celius Stingher
  • 17,835
  • 6
  • 23
  • 53
1

It's just:

df['col4']= (df['col1']+df['col2'])/df['col3']
jottbe
  • 4,228
  • 1
  • 15
  • 31