Przekształcanie za pomocą melt

Przekształcanie danych z pandas

Maria Eugenia Inzaugarat

Data Scientist

Transformacja z szerokiego do długiego formatu

  • Przeprowadzanie analiz
  • Wizualizacja różnych zmiennych na jednym wykresie
Przekształcanie danych z pandas

Transformacja z szerokiego do długiego formatu

Przekształcanie danych z pandas

Melt

Przekształcanie danych z pandas

Melt

Przekształcanie danych z pandas

Melt

Przekształcanie danych z pandas

Melt

Przekształcanie danych z pandas

Topienie danych

books
                             title isbn language pages
0                  Mostly Harmless  074      eng   260
1           The Hitchhiker's Guide  072      eng   215
2 El restaurante del fin del mundo  071      spa   250
books.melt(id_vars='title')
                              title  variable   value
0                   Mostly Harmless      isbn     074
1            The Hitchhiker's Guide      isbn     072
2  El restaurante del fin del mundo      isbn     071
3                   Mostly Harmless  language     eng
4            The Hitchhiker's Guide  language     eng
5  El restaurante del fin del mundo  language     spa
6                   Mostly Harmless     pages     260
7            The Hitchhiker's Guide     pages     215
8  El restaurante del fin del mundo     pages     250
Przekształcanie danych z pandas

Wartości i zmienne

 

Przekształcanie danych z pandas

Wartości i zmienne

 

Przekształcanie danych z pandas

Wartości i zmienne

 

Przekształcanie danych z pandas

Wartości i zmienne

 

Przekształcanie danych z pandas

Wybór wartości do topienia

books.melt(id_vars='title', value_vars=['language_code', 'num_pages'])
                              title  variable   value
0                   Mostly Harmless  language     eng
1            The Hitchhiker's Guide  language     eng
2  El restaurante del fin del mundo  language     spa
3                   Mostly Harmless     pages     260
4            The Hitchhiker's Guide     pages     215
5  El restaurante del fin del mundo     pages     250
Przekształcanie danych z pandas

Nadawanie nazw wartościom i zmiennym

books.melt(id_vars='title', value_vars=['language_code', 'isbn'], var_name='feature', value_name='code')
                              title   feature    code
0                   Mostly Harmless      isbn     074
1            The Hitchhiker's Guide      isbn     072
2  El restaurante del fin del mundo      isbn     071
3                   Mostly Harmless  language     eng
4            The Hitchhiker's Guide  language     eng
5  El restaurante del fin del mundo  language     spa
Przekształcanie danych z pandas

Czas na ćwiczenia!

Przekształcanie danych z pandas

Preparing Video For Download...