我有一个表,假设有两列a (list) B (list)和两行:
A: ["X", "Y"], ["Y", "Z"]
B: [1, 3], [5, 6]
我想实现像SELECT * FROM table WHERE A.Y = 5
这样的东西,它会返回一个(第二)行。我如何使用pyarrow.compute
实现这一点?
我正在研究pc.index_in
和pc.equals
,但他们不处理列表。我也试过C = StructArray.from_arrays([A, B])
,但再次,我不知道如何写SELECT * FROM table WHERE C.Y = 5
。
我也没有找到一个方法,来"normalize"/"unstack";通过使用Y
,表将变成:
A: ["X"], ["Z"]
B: [1], [6]
Y: 3, 5
这可能是一个错误的设计,但基本上我正在寻找两个函数,如Give me the vector of indexes of 'Y' in column A.
-这将返回[1,0]在上面的例子中
然后Give me the values from column B at index {the vector from the previous result, so [1,0]}
,这将导致[3,5]。
对于pyarrow中的列表数组,您可以使用list_flatten
和list_flatten_indices
来爆炸表:
import pandas as pd
import pyarrow as pa
import pyarrow.compute as pc
df = pd.concat(
[
pd.Series([["X", "Y"], ["Y", "Z"]], name="A"),
pd.Series([[1, 3], [5, 6]], name="B"),
],
axis=1,
)
table = pa.Table.from_pandas(df)
flat_table = pa.Table.from_arrays(
[
pc.list_flatten(table["A"]),
pc.list_flatten(table["B"]),
pc.list_parent_indices(table["A"]),
],
names=["A", "B", "index"],
)
相关内容
- appscript,在触发时从现有工作表中生成具有特定范围和工作表的新Google工作表文档
- c#自定义哈希表的迭代器
- 如何将数据表的行转换为列
- 如何在bootstrap 3表的搜索框旁边添加按钮
- 在Django中,如何使用外键将下拉列表与另一个表的数据绑定?
- 转换这种类型的表的最优雅的方式?
- 如何查询pyarrow表的struct字段
- 如何为多级索引/列dataframe更改pyarrow表的列精度
- 如何将PyArrow表转换为内存中的csv
- 将pandas DataFrame加载到十进制列的pyarrow表中
- 如何重新排序pyarrow表中的列
- 如何将Pandas数据帧转换为模式中具有并集类型的PyArrow表
- 将字符串键和数组值的嵌套字典转换为pyarrow表
- 有没有更惯用的方法可以根据列的内容从PyArrow表中选择行
- 在PyArrow中,如何将表的行追加到内存映射文件中
- Pyarrow表内存与原始csv大小的比较
- PyArrow表到PySpark数据帧的转换
- 逐行构建 pyarrow 表的最快方法
- 如何在python中的PyArrow和C++中的Arrow之间进行交互时将PyArrow表转换为Arrow表
- 拼花地板创建 从熊猫数据帧到 pyarrow 表的转换不适用于对象 dtype
最新更新
- 如果不同时更改当前头像,则无法更新用户详细信息
- Kotlin HTTP GET 数据并插入到文本视图中
- 滑块在移动设备上不跟随手指
- 释放WKNavigationAction子类在iOS 15上崩溃
- gst_video_time_code_is_valid在向流添加时间码时断言失败
- 如何杀死Mac上每次重新启动的进程?
- CMake:如何防止'target_link_libraries'将Visual Studio项目引用添加到静态库中?
- 飞镖编码/解码类不起作用
- ADF - Dynamic Sheet
- 无法使用处理程序保存图像。 "Physical path, but a virtual path was expected."
- 在挂载/卸载组件之间重用WebGL上下文
- 可以从Azure Blob Storage下载文件
- Flutter:选中复选框时如何更改标题:TextStyle ?
- 为什么在反应中手动改变状态是一个反模式?
- 我们如何从"git 日志"中排除"由'git notes add'添加的注释"?
- Python递归函数背后的逻辑
- numpy数组大小改变,可能表示二进制不兼容
- 如何在另一个选择菜单中使用来自一个选择菜单的消息
- 如何转换int值从csv到datetime在Spark SQL?
- 如何在同一行中添加输入和按钮
- 让加密403错误当在遗留(EOL)上安装certbot-auto时需要SNI错误
- C对文本文件中的整数进行选择排序,并将排序后的数字写入新文件
- 如何使Java Rest API在处理前半部分后返回响应,然后在返回响应后继续后半部分?
- SvelteKit未看到[id].苗条的文件
- Gitlab CI and php verstion
- ROS2-Gazebo:在立方体的一侧显示图像
- appery.模态离子1中的IO固定组件
- 一种检查is_explicit _constructible的方法
- 从电子表格自动填充谷歌文档
- 由CSS值更改触发的CSS动画
热门标签:
javascript python java c# php android html jquery c++ css ios sql mysql arrays asp.net json python-3.x ruby-on-rails .net sql-server django objective-c excel regex ruby linux ajax iphone xml vba spring asp.net-mvc database wordpress string postgresql wpf windows xcode bash git oracle list vb.net multithreading eclipse algorithm macos powershell visual-studio image forms numpy scala function api selenium