如何在使用Pyarrow编写镶木quet文件时提供镶木架模式
我有一个原始的输入CSV数据,其中所有字段均为字符串类型。我想将此CSV转换为镶木格式。但是,在转换为Parquet时,我想通过为数据提供自定义模式来编写它。我正在使用Pyarrow进行CSV进行镶木转换。
在使用Pyarrow编写文件时,如何提供自定义架构?
这是我使用的代码:
import pyarrow as pa
import pyarrow.parquet as pq
# records is a list of lists containing the rows of the csv
table = pa.Table.from_pylist(records)
pq.write_table(table,"sample.parquet")
I have a raw input csv data where all the fields are of string type. I want to convert this csv to parquet format. However on conversion to parquet I want to write it by providing a custom schema to the data. I am using PyArrow for csv to parquet conversion.
How can I provide a custom schema while writing the file to parquet using PyArrow?
Here is the code I used:
import pyarrow as pa
import pyarrow.parquet as pq
# records is a list of lists containing the rows of the csv
table = pa.Table.from_pylist(records)
pq.write_table(table,"sample.parquet")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能举一个记录例子吗?如果我尝试使用TU使用建议的失败列表:
我希望记录是文档中的命令列表。
在这种情况下,您可以在PY_LIST构建表时使用该模式:
Could you give an example of records? If I try tu use a list of lists as suggested fails:
I would expect records to be a list of dicts from the documentation.
You can use the schema when building the table from py_list, on this case: