mattrweaver 0 Newbie Poster

I have two dataframes and I need to separate rows where a value from pmdf matches one of the codes in jcrdf.All_codes.

If pmdf.code is in jcrdf.All_codes, I need a dataframe with all values from jcrdf AND pmdf.count.

Dataframes:

pmdf = pd.DataFrame(
        {
        'code': ['0567-8315','0007-4977','0096-0225','1365-2133','8675-309J'],
        'count':['6','7','10','2','1']
        }
        )

jcrdf = pd.DataFrame(
        {
        'jobtitle': ['manager','technician','noob','retiree'],
        'location': ['loc1','loc3','loc4','loc2'],
        'jcode' : ['4444-4444','3333-3333','2222-2222','1111-1111'],
        'All_codes': ['0096-0225,0096-0225','1820-7448,0567-8315,0567-8315','0007-4977,0007-4977','0007-0963,0007-0963,0366-077X,1365-2133']                        
         })

I have a lookup that allows for a diff:

jcrdf_lookup = pd.DataFrame(jcrdf['All_codes'].str.split(',').tolist(),
                                index=jcrdf.jcode).stack(level=0).reset_index(level=0)
    matches = jcrdf_lookup[jcrdf_lookup[0].isin(pmdf.code)]
    jcrdfmatch = jcrdf[jcrdf.jcode.isin(matches.jcode)]
    jcrdfnomatch = pmdf[~pmdf.code.isin(matches[0])]

But I can't figure out how to include pmdf.count.

I tried making a df of the unique codes from matches, but no matter what those values have to be in jcfdf.All_codes.

Thanks in advance, as usual, for any assistance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.