gpt4 book ai didi

How to load Parquet file with Pandas with specified dtypes?(如何加载带有指定数据类型的Pandas的拼图文件?)

转载 作者:bug小助手 更新时间:2023-10-24 22:09:48 26 4
gpt4 key购买 nike



How can I specify the data types I want with pd.read_parquet() like I can with
pd.read_csv()? When I try the same method I get an error saying pd.read_parquet has no dtype option.

如何才能像使用pd.read_csv()那样使用pd.read_parket()指定我想要的数据类型?当我尝试相同的方法时,我得到一个错误,说pd.read_parquite没有dtype选项。


dtypes={
'elapsed_time':np.int32,
'event_name':'category',
'name':'category',
'level':np.uint8,
'room_coor_x':np.float
'level_group':'category'}

dataset_df = pd.read_csv(path, dtype=dtypes)

更多回答
优秀答案推荐

It doesn't make sense to specify the dtypes for a parquet file. Unlike CSV files, parquet files store meta data with the type of each column. So the user doesn't have to specify them.

为拼图文件指定数据类型是没有意义的。与CSV文件不同,拼图文件存储具有每列类型的元数据。因此,用户不必指定它们。


If you want to change the type of the column you can always cast it using astype

如果要更改列的类型,始终可以使用astype对其进行转换


pd.read_parquet("my_file.parquet").astype(dtypes)

更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com