मेरे पास S3 पर एक टेक्स्ट फ़ाइल बची है जो एक टैब सीमांकित तालिका है। मैं इसे पांडा में लोड करना चाहता हूं, लेकिन इसे पहले नहीं बचा सकता क्योंकि मैं एक हरको सर्वर पर चल रहा हूं। यह है, जो कि अभी तक मेरे पास है।
import io
import boto3
import os
import pandas as pd
os.environ["AWS_ACCESS_KEY_ID"] = "xxxxxxxx"
os.environ["AWS_SECRET_ACCESS_KEY"] = "xxxxxxxx"
s3_client = boto3.client('s3')
response = s3_client.get_object(Bucket="my_bucket",Key="filename.txt")
file = response["Body"]
pd.read_csv(file, header=14, delimiter="\t", low_memory=False)
त्रुटि है
OSError: Expected file path name or file-like object, got <class 'bytes'> type
मैं प्रतिक्रिया निकाय को एक प्रारूप में कैसे परिवर्तित करूँगा जो पांडा स्वीकार करेंगे?
pd.read_csv(io.StringIO(file), header=14, delimiter="\t", low_memory=False)
returns
TypeError: initial_value must be str or None, not StreamingBody
pd.read_csv(io.BytesIO(file), header=14, delimiter="\t", low_memory=False)
returns
TypeError: 'StreamingBody' does not support the buffer interface
अद्यतन - निम्नलिखित कार्य का उपयोग करना
file = response["Body"].read()
तथा
pd.read_csv(io.BytesIO(file), header=14, delimiter="\t", low_memory=False)
io.BytesIO(file)
याio.StringIO(file)
के बजायfile
मेंread_csv()
कॉल