convert from string to pandas dataframe

Question:

I’m importing a csv file from AWS S3 in AWS Lambdawith below code:

file = s3.get_object(Bucket = bucket, Key = key)
rows = file['Body'].read().decode('utf-8').splitlines(False)

I’m getting input in below format :

data = “a,b,c,d,”x,y”,e,f”

and I want output in below format:

>>>`>>> df
   0  1  2  3    4  5  6
0  a  b  c  d  x,y  e  f`

i have to split data based on ‘,’ but if some thong is between ” ” they should remain as it is.

Or if you have any other solution for import csv file from s3 to lambda and converting in Data Frame, Please suggest

Asked By: prakhar kumar

||

Answers:

use csv module

try this,

from csv import reader
import pandas as pd
data=["a,b,c,d,"x,y",e,f"]
df=pd.DataFrame( list(reader(data)))
print df

Output:

   0  1  2  3    4  5  6
0  a  b  c  d  x,y  e  f
Answered By: Mohamed Thasin ah