There's more...

It is possible to recreate the original movie table by joining all the tables back together. First, join the associative tables to the actor/director tables. Then pivot the num column, and add the column prefixes back:

>>> actors = actor_associative.merge(actor_unique, on='actor_id') 
.drop('actor_id', 1)
.pivot_table(index='id',
columns='num',
aggfunc='first')

>>> actors.columns = actors.columns.get_level_values(0) + '_' +
actors.columns.get_level_values(1).astype(str)

>>> directors = director_associative.merge(director_unique,
on='director_id')
.drop('director_id', 1)
.pivot_table(index='id',
columns='num',
aggfunc='first')

>>> directors.columns = directors.columns.get_level_values(0) + '_' +
directors.columns.get_level_values(1)
.astype(str)

These tables can now be joined together with movie_table:

>>> movie2 = movie_table.merge(directors.reset_index(),
on='id', how='left')
.merge(actors.reset_index(),
on='id', how='left')
>>> movie.equals(movie2[movie.columns])
True
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset