Escaping few characters from csv file column in python

Viewed 29

I have a csv file as below

i have written code to explode json column into multiple rows but its not escaping characters like " and [, ] Example

INPUT -

T_i, u_i, number,json

1,19577125,41980366,'["hghjghjhvhjgjhghj", "jghjghjgjhghjgjgk"]


output

1,19577125,41980366,hghjghjhvhjgjhghj

1,19577125,41980366,jghjghjgjhghjgjgk

The put that i see from my code

output

1,19577125,41980366,["hghjghjhvhjgjhghj"

1,19577125,41980366,"jghjghjgjhghjgjgk]"

I have to escape characters like [ " " ]


My code any suggesstions?

importing pandas module

import pandas as pd

reading csv file from url

data = pd.read_csv("test.csv")

new data frame with split value columns

data['transaction_json'] = data['json'].str.split(',') data = data.explode('json')

Print the data

print(data)

0 Answers
Related