I'm working off a dataframe like the below. I've done my best to format it in SO. The important thing is that there are the same number of comma separated entries in person
, personparty
and sponsordate
(I've truncated the cells, so they may not be the same in this example but they are the same in the dataset).
bill status person personparty sponsordate
A bill to amend chapter 44 of title 18, .... 2ND Sen. David Vitter [R-LA] Republican 12/05/2015
A bill to authorize the appropriation of funds.... RESTRICT Sen. Ed Markey [D-MA], Sen. Ed Markey [D-MA], Sen. Ed Markey [D-MA], Sen. Barbara Boxer [D-CA] Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, Democrat, 21/05/2014, 02/06/2015, 05/04/2017, 22/05/2014, 21/07/2014, 09/06/2014, 02/06/2014, 12/06/2014, 21/05/2014, 02/06/2014, 21/05/2014
I want to create a new dataframe of five columns. I essentially want to unlist these (non list) values into one larger dataframe.
The final dataframe should have a row for the ith comma separated entry in , keeping the same column values for bill
and status
.
So for example from the second row in my example dataset, there would be a row with the bill name (A bill to authorize the appropriation of funds....), status (RESTRICT), Ed Markey, Democrat, 21/05/2014. The next row would be the 2nd entry from the comma separated values (same bill name, same status, Sen. Ed Markey [D-MA], Democrat, 02/06/2015), etc.
For rows with just one value in the three last columns, they'd stay the same.
How do I essentially unnest these list-like values?