1

I have a dataframe from pandas consisting of two columns, showing members delimited by a comma per date:

Date        Members
2009-01-30  [CHRW.OQ, AJG.N, CNP.N, WM.N, BA.N, LIN.N, WY....
2009-02-28  [CHRW.OQ, AJG.N, CNP.N, WM.N, BA.N, LIN.N, WY....
2009-03-30  [CHRW.OQ, AJG.N, CNP.N, WM.N, BA.N, LIN.N, WY....

I would like to transform that data that it shows for each member the the period it has been a member, i.e. data shall be transposed so that members are in the first row of a table, each member owning a row while the second column shows that first appearance date and the third column the last appearance date.

For this purpose, the first step that comes into my mind is to split the members delimited by coma into separate columns before transposing them into the rows and checking there appearance.

First simple code I have applied is this one:

df= df["Members"].str.split(',',expand=True)

However, this leads to the following output:

            Members
2009-01-30  NaN
2009-02-28  NaN

I highly appreciate your support, I am quite a newbie and I do also not have an idea how to proceed to get the final list desired.

Thank you very much in advance!

bencolo
  • 31
  • 2
  • 1
    Does this answer your question? [How to unnest (explode) a column in a pandas DataFrame?](https://stackoverflow.com/questions/53218931/how-to-unnest-explode-a-column-in-a-pandas-dataframe) – Roim Sep 26 '21 at 19:45

0 Answers0