我使用awswrangler来转换一个简单的dataframe,把它推到s3桶上,然后再读一遍。这是代码:
import boto3
import awswrangler as wr
import pandas as pd
test_bucket = 'test-bucket'
test_data = 'test_data.parquet'
s3 = boto3.client('s3')
df1 = pd.DataFrame(
[[1990, 1], [2000, 2], [1985, 6]], columns=["Feature1", "Feature2"]
)
wr.s3.to_parquet(df=df1, path=f"s3://{test_bucket}/{test_data}")
raw_data_s3_objects = s3.list_objects(Bucket=test_bucket)
for path in raw_data_s3_objects["Contents"]:
file_name = path["Key"]
raw_dataset = wr.s3.read_parquet(path=f"s3://{test_bucket}/{file_name}")当我打印原始数据(df1)和输出数据(raw_dataset)时,我得到(int64和Int64)数据类型
print(df1.dtypes)
print(raw_dataset.dtypes)
Feature1 int64
Feature2 int64
dtype: object
Feature1 Int64
Feature2 Int64
dtype: object从而导致数据格式不相等。这是窃听器还是我漏掉了什么?
发布于 2021-05-19 10:37:59
第一件事是,这里的区别是矮胖和熊猫类型的区别。int64代表numpy类型(np.int64),Int64代表熊猫类型(pd.Int64Dtype)。
这在https://github.com/awslabs/aws-data-wrangler/issues/580中有报道,这是有原因的,但在realease2.6.0中这是“固定的”。现在,您可以使用map_types参数(默认值为True,它执行您不想要的转换):
raw_dataset = wr.s3.read_parquet(path=f"s3://{test_bucket}/{file_name}", map_types=False)https://stackoverflow.com/questions/64119872
复制相似问题