我有一個非常寬的數(shù)據(jù)框(20,000 列),主要由 Pandas 中的 float64 列組成。我想將這些列轉(zhuǎn)換為 float32 并寫入 Parquet 格式。我這樣做是因為這些文件的下游用戶是內(nèi)存有限的小容器。我目前在 Pandas 中投射,但這在廣泛的數(shù)據(jù)集上非常慢,然后寫出鑲木地板。是否可以在寫入 to_parquet 過程本身時轉(zhuǎn)換類型?下面顯示了一個虛擬示例。import pandas as pdimport numpy as npimport pyarrowdf = pd.DataFrame(np.random.randn(3000, 15000)) # make dummy data setdf.columns = [str(x) for x in list(df)] # make column names string for parquetdf[list(df.loc[:, df.dtypes == float])] = df[list(df.loc[:, df.dtypes == float])].astype('float32') # cast the datadf.to_parquet("myfile.parquet") # write out the df
Pyarrow 在使用 Pandas to_parquet() 時應(yīng)用模式
慕運維8079593
2021-07-07 13:50:11