Lukas00990 2022-09-16 22:16 采纳率: 40.8%
浏览 142
已结题

pandas处理csv

用panda帮我处理下这个csv文件。

逻辑就是capability A, 由FingerGrasping, ForceApplying, Moving, Releasing组成,能不能在下面csv中,自动找到所有组合?并且限制是,ForceApplying 和Moving的DeviceID 需要一致。
同理,capability B, 由FingerGrasping, Moving, Realesing 组成,需要找到所有的组合。
capability C, Fixturing, MillingToolFunction, Spiining,Moving, ForceApplying 组成。

我的现在csv的第一列 相当于是子技能。 父技能由多个技能组成。比如capabilityA 由FingerGrasping, ForceApplying, Moving, Releasing。 但是 有个限制,就是ForceApplying 和 Moving 对应的deviceID应该一致,可以理解为是同一个device有两个子技能。
现在想要做的, 把capabilityA 由FingerGrasping, ForceApplying, Moving, Releasing。 所有排列组合找出来,并放在csv中

Capability name    Type    SimpleSkillID    Device    DeviceID
Moving    Moving    1    KUKA KR 270 R2700 ultra    R - 1
Moving    Moving    2    KUKA KR 270 R2900 K ultra    R - 2
Moving    Moving    3    ABB IRB 6700-150/3.20    R - 3
Moving    Moving    4    ABB IRB 6700-150/3.20 LeanID    R - 4
Moving    Moving    5    ABB IRB 6700-155/2.85    R - 5
Moving    Moving    6    Fanuc M-800iA/60    R - 6
Moving    Moving    7    Fanuc M-900iA/350    R - 7
Moving    Moving    8    Fanuc M-900iB/280    R - 8
Moving    Moving    9    Fanuc M-900iB/360    R - 9
Moving    Moving    10    Fanuc M-900iB/400L    R - 10
Moving    Moving    11    Fanuc M-900iB/700    R - 11
Moving    Moving    12    Fanuc M-2000iA/900L    R - 12
Moving    Moving    13    Fanuc M-2000iA/1700L    R - 13
Moving    Moving    14    Fanuc M-2000iC/210R    R - 14
ForceApplying    ForceApplying    15    KUKA KR 270 R2700 ultra    R - 1
ForceApplying    ForceApplying    16    KUKA KR 270 R2900 K ultra    R - 2
ForceApplying    ForceApplying    17    ABB IRB 6700-150/3.20    R - 3
ForceApplying    ForceApplying    18    ABB IRB 6700-150/3.20 LeanID    R - 4
ForceApplying    ForceApplying    19    ABB IRB 6700-155/2.85    R - 5
ForceApplying    ForceApplying    20    Fanuc M-800iA/60    R - 6
ForceApplying    ForceApplying    21    Fanuc M-900iA/350    R - 7
ForceApplying    ForceApplying    22    Fanuc M-900iB/280    R - 8
ForceApplying    ForceApplying    23    Fanuc M-900iB/360    R - 9
ForceApplying    ForceApplying    24    Fanuc M-900iB/400L    R - 10
ForceApplying    ForceApplying    25    Fanuc M-900iB/700    R - 11
ForceApplying    ForceApplying    26    Fanuc M-2000iA/900L    R - 12
ForceApplying    ForceApplying    27    Fanuc M-2000iA/1700L    R - 13
ForceApplying    ForceApplying    28    Fanuc M-2000iC/210R    R - 14
FingerGrasping    FingerGrasping    29    FingerGripper    E - 1
DrillBitFunction    DrillBitFunction    30    Drilling endeffector    E - 2
PressToolFunction    PressToolFunction    31    PressToolFunction    E - 3
ScrewingHeadFunction    ScrewingHeadFunction    32    Screwing Endeffector    E - 4
Fixturing    Fixturing    33    Milling Endeffector    E - 5
FingerGrasping    FingerGrasping    34    FingerGripper    E - 6
DrillBitFunction    DrillBitFunction    35    Drilling endeffector    E - 7
PressToolFunction    PressToolFunction    36    PressToolFunction    E - 8
ScrewingHeadFunction    ScrewingHeadFunction    37    Screwing Endeffector    E - 9
Fixturing    Fixturing    38    Milling Endeffector    E - 10
FingerGrasping    FingerGrasping    39    FingerGripper    E - 11
DrillBitFunction    DrillBitFunction    40    Drilling endeffector    E - 12
PressToolFunction    PressToolFunction    41    PressToolFunction    E - 13
ScrewingHeadFunction    ScrewingHeadFunction    42    Screwing Endeffector    E - 14
Fixturing    Fixturing    43    Milling Endeffector    E - 15
Releasing    Releasing    44    FingerGripper    E - 1
Press    Press    45    PressToolFunction    E - 3
SpinningTool    SpinningTool    46    Screwing Endeffector    E - 4
MillingToolFunction    MillingToolFunction    47    Milling Endeffector    E - 5
Releasing    Releasing    48    FingerGripper    E - 6
Press    Press    49    PressToolFunction    E - 8
SpinningTool    SpinningTool    50    Screwing Endeffector    E - 9
MillingToolFunction    MillingToolFunction    51    Milling Endeffector    E - 10
Releasing    Releasing    52    FingerGripper    E - 11
Press    Press    53    PressToolFunction    E - 13
SpinningTool    SpinningTool    54    Screwing Endeffector    E - 14
MillingToolFunction    MillingToolFunction    55    Milling Endeffector    E - 15
Spinning    Spinning    56    Milling Endeffector    E - 5
Spinning    Spinning    57    Milling Endeffector    E - 10
Spinning    Spinning    58    Milling Endeffector    E - 15
Metrology    Metrology    59    Leica AT901-MR    M - 1
Metrology    Metrology    60    Leica AT960-MR    M -2
Metrology    Metrology    61    T-Mac Inspect with/without touch trigger probe*    M - 3
Metrology    Metrology    62    T-Mac Frame    M - 4
Metrology    Metrology    63    T-Scan5    M - 5
Metrology    Metrology    64    Reflectors    M - 6
Metrology    Metrology    65    T-Probe    M - 7
Metrology    Metrology    66    Nikon MV331    M - 8
Metrology    Metrology    67    V-Stars Dual Camera system (model DynaMo 12)    M - 9
Metrology    Metrology    68    V-Stars probe    M - 10
 

  • 写回答

1条回答 默认 最新

  • 侯小啾 Python领域优质创作者 2022-09-16 23:31
    关注

    您好,功能已经实现,如有帮助还请采纳。

    import pandas as pd
     
     
    df = pd.read_csv('data.csv')
     
    # 所有子技能的种类
    all_cap = set(df['Capability'].values.tolist())
     
     
    # 汇总每个子技能,对应的'DeviceID'有哪些
    dict1 = {}
    for c in all_cap:
        dev_sets = df.loc[df['Capability'] == c]['DeviceID'].values.tolist()
        dict1[c] = dev_sets
     
     
    # 1.capabilityA的组合
    # 对"Moving""ForceApplying":显而易见 "Moving""ForceApplying" 共有14种选择,即(R - 1,R - 1) 到(R - 14,R - 14),且必须保持一致
    # 然后我们首先考虑"FingerGrasping""Releasing",输出的顺序依次是["FingerGrasping", "Releasing","Moving", "ForceApplying"]
    cap_A = []
    for a in dict1["FingerGrasping"]:
        for b in dict1["Releasing"]:
            for cd in dict1["Moving"]:
                z=[]
                z.append(a)
                z.append(b)
                z.append(cd)
                z.append(cd)
                cap_A.append(z)
     
     
    # 2.capabilityB的组合  
    # 输出的顺序是["FingerGrasping", "Realesing",  "Moving"]
    cap_B = []
    for a in dict1["FingerGrasping"]:
        for b in dict1["Releasing"]:
            for c in dict1["Moving"]:
                z=[]
                z.append(a)
                z.append(b)
                z.append(c)
                cap_B.append(z)
     
     
    # 3.capabilityC的组合 
    # 输出的顺序是["Fixturing", "MillingToolFunction", "Spinning", "Moving", "ForceApplying"]
    cap_C = []
    for a in dict1["Fixturing"]:
        for b in dict1["MillingToolFunction"]:
            for c in dict1["Spinning"]:
                for de in dict1["Moving"]:
                    z=[]
                    z.append(a)
                    z.append(b)
                    z.append(c)
                    z.append(de)
                    z.append(de)
                    cap_C.append(z)
     
     
    capab = ["capabilityA"] * len(cap_A) + ["capabilityB"] * len(cap_B) + ["capabilityC"] * len(cap_C)
    capab_combination = cap_A + cap_B + cap_C
     
    result = pd.DataFrame({"capab": capab,
                           "capab_combination":capab_combination})
     
    print(result)
    result.to_csv("result.csv",index=False)
    

    输出的csv效果如下:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 9月25日
  • 已采纳回答 9月17日
  • 修改了问题 9月16日
  • 创建了问题 9月16日

悬赏问题

  • ¥15 综合布线实例设计,就好看好看不恐怖可好滤镜好聚
  • ¥15 使用moviepy库视频合并时出错
  • ¥30 FLUENT液固传质UDF
  • ¥15 怎么看梯度直方图以,怎么判断梯度消失/爆炸,怎么解决
  • ¥15 aspnetdll文件访问拒绝
  • ¥15 wpf中在模版中寻找元素
  • ¥15 MFC平台生成指定圆
  • ¥15 jmeter出现403
  • ¥500 求华为P30PRO手机硬盘数据恢复
  • ¥15 关于#vscode#的问题:ESP32开发板对接MQTT实现小灯泡的开关