I have this byte object that I read from csv in s3 bucket (not the whole object):
b'00032501;2020-03-03;-;00:00:00;00:59:03;60;3543;1;0;0\r\n00032502;2020-03-03;-;00:00:00;00:59:03;60;3543;1;0;0\r\n00067601;2020-03-03;RTL;00:00:00;00:20:19;5;1219;1;1;0\r\n00067601;2020-03-03;VOX;00:20:19;00:59:27;8;2348;1;1;0\r\n00102204;2020-03-03;-;00:00:00;00:21:56;24;1316;2;1;1\r\n00170201;2020-03-03;-;00:00:00;00:59:50;62;3590;1;0;0\r\n00170202;2020-03-03;-;00:00:00;00:59:50;62;3590;1;0;0\r\n00170801;2020-03-03;ZDF;00:00:00;00:10:13;3;613;1;1;0\r\n00187202;2020-03-03;-;00:00:00;00:24:08;26;1448;1;0;0\r\n00339802;2020-03-
How can I put it in dataframe? Now I am using io.BytesIO
to read the data, but when I put it in dataframe with df = pd.read_csv(io.BytesIO object, dtype=str, sep=';')
, it is not separated properly, all the columns are inside the first one. When I use sep=';'
it does nothing.
s3 = boto3.client("s3")
if event:
file_obj = event["Records"][0]
filename = str(file_obj['s3']['object']['key'])
f_obj = s3.get_object(Bucket = bucket, Key = filename)
print(f_obj)
file_content = f_obj["Body"].read()
data = io.BytesIO(file_content)
df = pd.read_csv(data)
print(df)