3

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

0

1 Answer 1

7

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.