0

From 2 series objects, which contain dogs colors I try to create 1 DataFrame object where each column is a dogs breed, and each row a color.

I've transformed 2 series objects into data_frame objects and grouped each on color.

poodle = pd.Series(['grey', 'grey', 'white', 'white', 'black', 'black'])
shihtzu = pd.Series(['grey', 'white', 'white', 'white', 'white', 'black'])

poodle = poodle.to_frame()
poodle.columns = ['poodle_color']
poodle = poodle.groupby('poodle_color').poodle_color.count().to_frame()

shihtzu = shihtzu.to_frame()
shihtzu.columns = ['shihtzu_color']
shihtzu = shihtzu.groupby('shihtzu_color').shihtzu_color.count().to_frame()

dogs = pd.merge(
    poodle,
    shihtzu,
    left_on='poodle_color',
    right_on='shihtzu_color', suffixes=['poodle', 'shihtzu'])

print(dogs)

Expected result should look like this:

pivot table

Actual output is: Empty DataFrame Columns: [poodle_color, shihtzu_color] Index: []

Alex Ivanov
  • 461
  • 1
  • 10
  • Use `dogs = pd.merge( poodle, shihtzu, left_index=True, right_index=True, suffixes=['poodle', 'shihtzu'])` – jezrael Aug 07 '19 at 11:52
  • 1
    jezrael, thank you very much. I've learnt documentation. left_index and right_index parameters mean that we join on their basis. I will use it. – Alex Ivanov Aug 07 '19 at 13:39

0 Answers0