Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- data = pd.DataFrame({
- 'estA': [1., 2., 3., 4.],
- 'estB': [5., 6., 7., 8.],
- 'estC': [8., 7., 6., 5.],
- 'estZ': [0., 3., 0., 1.],
- })
- #print(data)
- Am = data['estA'].mean()
- Bm = data['estB'].mean()
- Cm = data['estC'].mean()
- Zm = data['estZ'].mean()
- #print(Am, Bm, Cm, Zm)
- for index, row in data.iterrows():
- if row['estZ'] == 0:
- row['estZ'] = Zm/len(data) * (Am/row['estA'] + Bm/row['estB'] + Cm/row['estC'])
- print(data)
- #-------------------------------------
- data = pd.DataFrame({
- 'estA': [1., 2., 3., 4.],
- 'estB': [5., 6., 7., 8.],
- 'estC': [8., 7., 6., 5.],
- 'estZ': [0., 3., 0., 1.],
- })
- #print(data)
- Am = data['estA'].mean()
- Bm = data['estB'].mean()
- Cm = data['estC'].mean()
- Zm = data['estZ'].mean()
- #print(Am, Bm, Cm, Zm)
- subset = data[ data['estZ'] == 0 ]
- for index, row in subset.iterrows():
- data['estZ'][index] = Zm/len(data) * (Am/row['estA'] + Bm/row['estB'] + Cm/row['estC'])
- print(data)
- #-------------------------------------
- data = pd.DataFrame({
- 'estA': [1., 2., 3., 4.],
- 'estB': [5., 6., 7., 8.],
- 'estC': [8., 7., 6., 5.],
- 'estZ': [0., 3., 0., 1.],
- })
- #print(data)
- Am = data['estA'].mean()
- Bm = data['estB'].mean()
- Cm = data['estC'].mean()
- Zm = data['estZ'].mean()
- data['estZ'] = data.apply(lambda row: row['estZ'] if row['estZ'] != 0 else Zm/len(data) * (Am/row['estA'] + Bm/row['estB'] + Cm/row['estC']), axis=1)
- print(data)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement