0

I'm working with Python Pandas DataFrames and I'd like to split one cell into two by checking if a Substring appears in a list. I export the Data from an Excel-file.

The export:

excel = pd.read_excel(r'./data.xlsx')

This is how the data looks like if I print it: Data

This is my list that I'd like to use for splitting the cell:

doks = ["CCS CSC", "COBIT 5", "ISA 62443-2-1:2009", "ISA 62443-3-3:2013", "ISO/IEC 27001:2013",
"ISO/IEC 27019:2013", "BSI-Standard", "NIST SP 800-53 Rev. 4", "CIS CSC", 
"NIST SP 800-53", "IEC 62351-8", "NERC CIP-002", "NERC CIP-003", "NERC CIP-004", "NERC CIP-005",  
"NERC CIP-006", "NERC CIP-006, 007" "NERC CIP-007", "NERC CIP-008", "NERC CIP-009"]

This is my current status where I'm stuck:

def find_chapter(fullRef, dokuments):
for dokument in dokuments:
    if dokument in fullRef:
        chapter = fullRef.split(dokument)[-1]
        return chapter

excel["Kapitel"] = excel.apply(lambda x: find_chapter(x["Referenzen"], doks), axis=1)
swissmount
  • 5
  • 2
  • 7
  • Can you show what a sample output dataframe looks like? – Parmandeep Chaddha Mar 15 '21 at 15:11
  • Hi, yes, I've linked it in the question on the "Data" link – swissmount Mar 15 '21 at 15:21
  • From what I understand, this might be a duplicate. https://stackoverflow.com/questions/14745022/how-to-split-a-dataframe-string-column-into-two-columns. For your case, it would be: `excel = pd.DataFrame(excel['Referenzen"].str.split(doks).tolist(), columns=["Referenzen, Kapitel"])` – Parmandeep Chaddha Mar 15 '21 at 20:46
  • Hi, no unfortunatly not. When I use this code I get "TypeError: unhashable type: 'list'". Do you have an idea how to fix this? – swissmount Mar 16 '21 at 07:18

0 Answers0