How can I replace the specific digits in columns of pandas data frame without affecting other characters? I have a large csv file which is something similar like this:
data = pd.read_csv("meter.csv")
data.head()
Out[10]:
value temp1 temp2
0 34 02:0 16.0 17
1 36 06:0 8.0 27
2 28 10:0 18.0 21
3 34 02:0 16.0 17
4 36 06:0 8.0 27
5 28 10:0 18.0 21
6 34 02:0 16.0 17
7 36 06:0 8.0 27
8 28 10:0 18.0 21
I want to replace value column values if value.str[3:5] == 10 with 00
Output that I need:
value temp1 temp2
0 34 02:0 16.0 17
1 36 06:0 8.0 27
2 28 00:0 18.0 21
3 34 02:0 16.0 17
4 36 06:0 8.0 27
5 28 00:0 18.0 21
6 34 02:0 16.0 17
7 36 06:0 8.0 27
8 28 00:0 18.0 21
I tried with using pd.str.replace reference:pandas.Series.str.replace. but could not able to achieve it.
My code: data['value'] = data['value'].str[3:5].replace('10','00') and this gives output:
value temp1 temp2
0 02 16.0 17
1 06 8.0 27
2 00 18.0 21
3 02 16.0 17
4 06 8.0 27
5 00 18.0 21
It is replacing entire values with new value. Could anyone help me to solve this. Thanks!