Question: Using this code I have write/replace data in an excel file. But now i need to do the same thing for csv file. Can someone help me with that?

```py
with pd.ExcelWriter('2.xlsx', mode='a', engine='openpyxl', if_sheet_exists='replace') as writer:  
    fm_data.to_excel(writer, sheet_name='Raw Data1') 

```

Answer: 
Assuming you know there are only 2 columns *and* the second column is always a floating-point number (when there are any), you can use this:

```
awk -F, 'NF == 3 { $0 = $1FS$2"."$3 } NF == 4 { $0 = $1"."$2FS$3"."$4 } 1' infile

```
The question is internally inconsistent. I will assume if a line has 3 commas then we want to change the first and last comma to a period. Otherwise the line has 2 commas and we only want to change the last comma to a period:

```
$ sed -E '/(,[^,]+){3}/ { s/^([^,]+),/\1./ }; s/,([^,]+)$/.\1/' P7.csv
30,-4.098511E-02
30.05,-4.098511E-02
66.7,-1.865433

```

I suggest you regenerate the data from the original source in an unambitious format if at all possible. The heuristic you asked us to implement which may introduce (data) errors.

This invocation you mention will modify the file P7.csv and write a blank file P7\_test.csv. This is probably not what you want (where ... is some script):

```
sed -i ... P7.csv > P7_test.csv

```