I have DataFrame
id,type,value
1,8,value1
2,2,value2
3,7,value3
4,3,value4
5,10,value5
6,3,value16
I want to add to the value id
and value
of the CSV file to be allocated quotes
"1",8,"value1"
"2",2,"value2"
What better way to do it
So quote characters are used in CSV files when the text within a field also includes a comma and could be confused as being the reserved comma delimiter for the next field. Quote characters indicate the start and end of a block of text where any comma characters can be ignored.
converting to strings and using +
df.update('"' + df[['id', 'value']].astype(str) + '"')
print(df)
using applymap
df.update(df[['id', 'value']].applymap('"{}"'.format))
print(df)
Both yield
id type value
0 "1" 8 "value1"
1 "2" 2 "value2"
2 "3" 7 "value3"
3 "4" 3 "value4"
4 "5" 10 "value5"
5 "6" 3 "value16"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With