How can i directly replace a row & column data in a csv file or in data frame?

Viewed 24
 p   q   r  s     t
130 111 21  27  13495
130 111 21  27  16500
152 154 19  26  16500
109 102 24  30  13950
136 115 18  22  17450
136 110 19  25   5250
136 110 19  25  17710
136 110 19  25  18920
131 140 17  20  23875
131 160 16  22  12000
108 101 23  29  16430
108 101 23  29  16925

In this data frame how to replace t column less than 10000 value in average of total t column?

1 Answers

Do you want this?

df.loc[df['t'] < 10000] =df['t'].mean()

or

import numpy as np
df['t'] = np.where(df['t'] < 10000 , df['t'].mean() , df['t'])
Related