Miaomiao
Miaomiao

Reputation: 69

how to catenate values in dataframe

enter image description here

Hello,

i have a question about how to catenate elements in a dataframe. For example, i have a dataframe like in the picture. How could i catenate 2015-10-01 with 2015-10-04, 2015-10-13 with 2015-10-15, 2015-10-28 with 2015-10-29, 2015-10-30 with 2015-10-31. At the end, i could get the combination like:

res=[(2015-10-01,2015-10-04),(2015-10-13,2015-10-15),(2015-10-28,2015-10-29),(2015-10-30,2015-10-31)]

Upvotes: 2

Views: 37

Answers (2)

jezrael
jezrael

Reputation: 862406

If logic is join by rows with missing values in another column use zip with filtered rows in DataFrame.loc with masks by Series.isna:

res = list(zip(df.loc[df['End_Date'].isna(), 'Start_date'], 
               df.loc[df['Start_date'].isna(), 'End_Date']))

Upvotes: 2

Molessia
Molessia

Reputation: 473

If you want to concatenate the value in the column "Start_Date" with the value in the column "End_Date", you can do this:

res = list(dataset[['Start_Date', 'End_Date']].itertuples(index=False, name=None))

Upvotes: 0

Related Questions