0

I have the following data frame:

enter image description here

After I perform this operation:

pages  = df_ref.groupby("KV").work_p.unique().reset_index()

I'm getting the new dataframe where the data type of the column work_p is an array. How can I extract/convert it to integer?

I feel like I can achieve the goal also by changing the first step, but as I am new to pandas I, unfortunately, stuck.

enter image description here

as5
  • 515
  • 1
  • 4
  • 7
  • 2
    Please provide a small set of sample data as text that we can copy and paste. Include the corresponding desired result. Check out the guide on [how to make good reproducible pandas examples](https://stackoverflow.com/a/20159305/3620003). – timgeb Jun 12 '20 at 13:27
  • Also, what if the lists in the work_p column have more than one element? – timgeb Jun 12 '20 at 13:29

1 Answers1

0

Try:

pages['work_p'] = pages.work_p.apply(lambda x: x[0])
CHRD
  • 1,917
  • 1
  • 15
  • 38
  • 1
    `df_ref.groupby("KV").work_p.first()` should be used. Instead of grouping and again using apply on that. The question is vague it doesn't say anything about how to handle when there no duplicates. Please answer only well-asked question, saves times and frustration ;) – Ch3steR Jun 12 '20 at 13:48