我有一个pandas DataFrame,我想上传到新的CSV文件.问题是我不想在将文件传输到s3之前将其保存在本地.是否有像to_csv这样的方法直接将数据帧写入s3?我正在使用boto3.
这是我到目前为止:
import boto3
s3 = boto3.client('s3', aws_access_key_id='key', aws_secret_access_key='secret_key')
read_file = s3.get_object(Bucket, Key)
df = pd.read_csv(read_file['Body'])
# Make alterations to DataFrame
# Then export DataFrame to CSV through direct transfer to s3
Run Code Online (Sandbox Code Playgroud) 我有一个 python 对象,我知道这是加载到该对象的镶木地板文件。(我无法实际从文件中读取它)。
该对象var_1包含b'PAR1\x15\x....1\x00PAR1
当我检查类型时:
type(var_1)
Run Code Online (Sandbox Code Playgroud)
我得到的结果是bytes.
有办法阅读这个吗?说成熊猫数据框?
我尝试过: 1)
from fastparquet import ParquetFile
pf = ParquetFile(var_1)
Run Code Online (Sandbox Code Playgroud)
并得到:
TypeError: a bytes-like object is required, not 'str'
Run Code Online (Sandbox Code Playgroud)
2
import pyarrow.parquet as pq
dataset = pq.ParquetDataset(var_1)
Run Code Online (Sandbox Code Playgroud)
并得到:
TypeError: not a path-like object
Run Code Online (Sandbox Code Playgroud)
注意, How to read a Parquet file into Pandas DataFrame?的解决方案 。即pd.read_parquet(var_1, engine='fastparquet')导致TypeError: a bytes-like object is required, not 'str'