如何在Python中创建数据框的子集?
我有一个大型数据集(Pandes DataFrame),带有以下标题ram = [f“ rut1_azi_ {i}”在范围(10)]
rdp = [f“ rut1_dtctn_probb_ {i}” for range in range(´10)]
rdi = [f“ rut1_dtctn_id_ {i}” for range(10)]
rem = [f“ rut1_elev_ {i}” for Range(10)]
rcc = ['rut1_cycle_counter']
现在我想从原始数据框架中进行许多子集,如下所示。
subset_0index,rut1_cycle_counter,rut1_azi_0,rut1_dtctn_probb_0,rut1_dttctn_id_0,rut1_elev_0
subset_1 subset_1index,rut1_cycle_counter,rut1_azi_1,rut1_dtctn_probb_1,rut1_dttctn_id_1,rut1_elev_1
。
。
。
subset_9index,rut1_cycle_counter,rut1_azi_9,rut1_dtctn_probb_9,rut1_dttctn_id_9,rut1_elev_9
我如何在python中执行此操作? 我是Python的初学者,
非常感谢您
I have a large dataset(pandes dataframe) with following headersRAM = [f"RUT1_Azi_{i}" for i in range(10)]
RDP = [f"RUT1_Dtctn_Probb_{i}" for i in range(´10)]
RDI = [f"RUT1_Dtctn_ID_{i}" for i in range(10)]
REM = [f"RUT1_Elev_{i}" for i in range(10)]
RCC = ['RUT1_Cycle_Counter']
Now i want to make many subset from the original dataframe as below.
subset_0index,RUT1_Cycle_Counter, RUT1_Azi_0, RUT1_Dtctn_Probb_0, RUT1_Dtctn_ID_0, RUT1_Elev_0
subset_1index,RUT1_Cycle_Counter, RUT1_Azi_1, RUT1_Dtctn_Probb_1, RUT1_Dtctn_ID_1, RUT1_Elev_1
.
.
.
subset_9index,RUT1_Cycle_Counter, RUT1_Azi_9, RUT1_Dtctn_Probb_9, RUT1_Dtctn_ID_9, RUT1_Elev_9
How can I do this in python?
i am a beginner in python
Thank you very much in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个示例:
现在:
例如:
编辑:修改答案以包括所有子集的常见列列表(
rcc = ['rut1_cycle_counter']
):Here is an example:
Now:
For example:
Edit: modified answer to include a common list of columns for all subsets (
RCC = ['RUT1_Cycle_Counter']
):使用 pandas,您可以本机调用数据帧的子集
只要
list_of_subset_headers
是数据帧列的子集,只需编写Or 在这种情况下:
With pandas you can natively call a subset of a dataframe
as long as
list_of_subset_headers
is a subset of your dataframes columns just writeOr in this case :