pandas split and melt()

Sayth Renshaw flebber.crue at gmail.com
Wed Jun 26 02:46:12 EDT 2019


> > NB. There are varied amounts of consultants so splitting across columns is uneven. if it was even melt seems like it would be good https://dfrieds.com/data-analysis/melt-unpivot-python-pandas
> 
> Keep it simple: https://docs.python.org/3.6/library/string.html
> 
> -- 
> Regards =dn

I have managed to split but not filter the numbers. All other code being the same.
...
completed_tasks = df.loc[(df['Completed'] == 'Yes') & (df['Motor/Property'] == 'Motor') & (df['Delivery Method'] == 'Group Coaching')]
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";")
pattern = "\\#d"
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";")
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.contains(pattern)
...

Works without the regex which causes this error AttributeError: Can only use .str accessor with string values, which use np.object_ dtype

pattern = "\\#d"
completed_tasks['Consultant'] = completed_tasks['Consultant'].str.split(pat = ";")

Sayth



More information about the Python-list mailing list