I have a dataset about gun violence for a project. One of the columns includes the participant types, either victim or subject/suspect. The participant column has multiple values within it for each participant in the incident.
import pandas as pd
data = pd.read_csv('Gun violence Shortened version.csv')
data.head()
Output:
incident_id date state participant_type
0 461105 1/1/2013 Pennsylvania 0::Victim||1::Victim||2::Victim||3::Victim||4:...
1 460726 1/1/2013 California 0::Victim||1::Victim||2::Victim||3::Victim||4:...
2 478855 1/1/2013 Ohio 0::Subject-Suspect||1::Subject-Suspect||2::Vic...
3 478925 1/5/2013 Colorado 0::Victim||1::Victim||2::Victim||3::Subject-Su...
4 478959 1/7/2013 North Carolina 0::Victim||1::Victim||2::Victim||3::Subject-Su...
I want to take each participant and give them their own row while keeping incident_id
and date the same:
incident_id date state participant_type
0 461105 1/1/2013 Pennsylvania Victim
1 461105 1/1/2013 Pennsylvania Victim
2 461105 1/1/2013 Pennsylvania Victim
3 461105 1/1/2013 Pennsylvania Subject-Suspect *this was the 4:: instance that was cut off earlier*
I'm not sure how to accomplish this. I've seen example of splitting a column into two but not how to take from a column into a row.