0

I have the following sort of df:

c1           c2
foo123123   [bar782348, baz23423, foo423423423]
bar738475   [baz234234, foo4234234]
baz2323234  []

I need to map each value from c1 to each item of lists of c2 like

c1          c2
foo123123   bar782348
foo123123   baz23423
foo123123   foo423423423

bar738475   baz234234
bar738475   foo4234234

i can do this using apply in a rather weird way, but the speed does not work for me, as well as the code readability.

result = pd.DataFrame()
def func(row):
    global result
    df = pd.DataFrame([row['refs']], index=[row['id']]).stack().to_frame()
    df = df[[0]].reset_index()
    result = result.append(df)

df.apply(func,axis=1)

I am sure this can be done via numpy arrays manipulations, but I yet had not had much experience with numpy.

Thank you!

Dmitriy Grankin
  • 568
  • 9
  • 21

0 Answers0