【发布时间】:2021-01-04 02:22:00
【问题描述】:
假设我有一个这种结构的数据框:
╔══════════════════════════════════════╦══════════════════╦════════════╦═══════════╦════════════════════╦══════════════╦══════════════════════╦═════════════════════╦═════════════════════════════════╦════════════════════════════════════════════╦════════════════════════════════════════════╗
║ candidate_id ║ public_id ║ first_name ║ last_name ║ email ║ phone_number ║ company_name ║ years_of_experience ║ normalized_degree ║ college_name ║ specialization_path ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╣
║ a132a4f9-fa42-4802-8958-228952240d47 ║ divyanshu-thakur ║ Divyanshu ║ Thakur ║ xxx@gmail.com ║ xxxx ║ Google ║ 3 ║ Bachelor's / Undergraduate ║ Indian Institute of Information Technology ║ Technical / Quantitative~>Computer Science ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╣
║ 71cfc6b7-b601-4ca0-b894-0b9f48dad717 ║ kami-kms ║ Kami ║ Kms ║ xxxxxx@yahoo.com ║ xxxxxxx ║ Groupon ║ 2 ║ High School Certificate/Diploma ║ Board of Education ║ Technical / Quantitative~>Statistics ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╣
║ 71cfc6b7-b601-4ca0-b894-0b9f48dad717 ║ kami-kms ║ Kami ║ Kms ║ xxxxxx@yahoo.com ║ xxxxxxx ║ Groupon ║ 2 ║ Bachelor's / Undergraduate ║ ISBM University ║ Technical / Quantitative~>Statistics ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╣
║ 8af6be9a-007e-4cfa-9965-aa65948e945f ║ kundan-mishra ║ KUNDAN ║ MISHRA ║ xxxxxxxx@gmail.com ║ xxxxxxxx ║ Mobikwik ║ 8 ║ Master's / Graduate ║ IIM ║ Business / Commerce~>Marketing ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╣
║ 8af6be9a-007e-4cfa-9965-aa65948e945f ║ kundan-mishra ║ KUNDAN ║ MISHRA ║ xxxxxxxx@gmail.com ║ xxxxxxx ║ OYO - Vacation Homes ║ 8 ║ Master's / Graduate ║ IIM ║ Business / Commerce~>Marketing ║
╚══════════════════════════════════════╩══════════════════╩════════════╩═══════════╩════════════════════╩══════════════╩══════════════════════╩═════════════════════╩═════════════════════════════════╩════════════════════════════════════════════╩════════════════════════════════════════════╝
我想使用candidate_id 字段对所有元素进行分组。
所以,我想要的是:
╔══════════════════════════════════════╦══════════════════╦════════════╦═══════════╦════════════════════╦══════════════╦═══════════╦══════════════════════╦═════════════════════╦═════════════════════════════════╦════════════════════════════════════════════╦════════════════════════════════════════════╦════════════════════════════╦═════════════════╦══════════════════════════════════════╗
║ candidate_id ║ public_id ║ first_name ║ last_name ║ email ║ phone_number ║ company_1 ║ company_2 ║ years_of_experience ║ normalized_degree1 ║ college_name1 ║ specialization_path1 ║ normalized_degree2 ║ college_name2 ║ specialization_path2 ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬═══════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════╬═════════════════╬══════════════════════════════════════╣
║ a132a4f9-fa42-4802-8958-228952240d47 ║ divyanshu-thakur ║ Divyanshu ║ Thakur ║ xxx@gmail.com ║ xxxx ║ Google ║ NA ║ 3 ║ Bachelor's / Undergraduate ║ Indian Institute of Information Technology ║ Technical / Quantitative~>Computer Science ║ NA ║ NA ║ NA ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬═══════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════╬═════════════════╬══════════════════════════════════════╣
║ 71cfc6b7-b601-4ca0-b894-0b9f48dad717 ║ kami-kms ║ Kami ║ Kms ║ xxxxxx@yahoo.com ║ xxxxxxx ║ Groupon ║ NA ║ 2 ║ High School Certificate/Diploma ║ Board of Education ║ Technical / Quantitative~>Statistics ║ Bachelor's / Undergraduate ║ ISBM University ║ Technical / Quantitative~>Statistics ║
╠══════════════════════════════════════╬══════════════════╬════════════╬═══════════╬════════════════════╬══════════════╬═══════════╬══════════════════════╬═════════════════════╬═════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════════════════════╬════════════════════════════╬═════════════════╬══════════════════════════════════════╣
║ 8af6be9a-007e-4cfa-9965-aa65948e945f ║ kundan-mishra ║ KUNDAN ║ MISHRA ║ xxxxxxxx@gmail.com ║ xxxxxxxx ║ Mobikwik ║ OYO - Vacation Homes ║ 8 ║ Master's / Graduate ║ IIM ║ Business / Commerce~>Marketing ║ NA ║ NA ║ NA ║
╚══════════════════════════════════════╩══════════════════╩════════════╩═══════════╩════════════════════╩══════════════╩═══════════╩══════════════════════╩═════════════════════╩═════════════════════════════════╩════════════════════════════════════════════╩════════════════════════════════════════════╩════════════════════════════╩═════════════════╩══════════════════════════════════════╝
除了蛮力之外,我找不到任何其他方法。
【问题讨论】:
标签: python-3.x pandas dataframe group-by