Python Pandas Tutorial 12. Stack Unstack




[ad_1]

Pandas stack method is used to transpose innermost level of columns in a dataframe. unstack() is used to perform a reverse operation. This tutorial explains stack/unstack using nice visualizations.

Topics that are covered in this Python Pandas Video:
0:00 What is stack
1:32 How to use stack() method
2:18 Pandas stack documentation
3:03 Perform unstack() method

code: https://github.com/codebasics/py/blob/master/pandas/12_stack/12_pandas_stack.ipynb

To download csv and code for all tutorials: go to https://github.com/codebasics/py, click on a green button to clone or download the entire repository and then go to relevant folder to get access to that specific file.

Next Video:
Python Pandas Tutorial 13. Crosstab: https://www.youtube.com/watch?v=I_kUj-MfYys&list=PLeo1K3hjS3uuASpe-1LjfG5f14Bnozjwy&index=13

Popular Playlist:
Complete python course: https://www.youtube.com/playlist?list=PLeo1K3hjS3uv5U-Lmlnucd7gqF-3ehIh0

Data science course: https://www.youtube.com/playlist?list=PLeo1K3hjS3us_ELKYSj_Fth2tIEkdKXvV

Machine learning tutorials: https://www.youtube.com/playlist?list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw

Pandas tutorials: https://www.youtube.com/playlist?list=PLeo1K3hjS3uuASpe-1LjfG5f14Bnozjwy

Git github tutorials: https://www.youtube.com/playlist?list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW

Matplotlib course: https://www.youtube.com/playlist?list=PLeo1K3hjS3uu4Lr8_kro2AqaO6CFYgKOl

Data structures course: https://www.youtube.com/playlist?list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12

Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub

Source


[ad_2]

Comment List

  • codebasics
    December 2, 2020

    Step by step guide on how to learn data science for free: https://www.youtube.com/watch?v=Vn_mmOuQkSA
    Machine learning tutorials with exercises:
    https://www.youtube.com/watch?v=gmvvaobm7eQ&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw

  • codebasics
    December 2, 2020

    hello sir , i like your tutorials on pandas very much . i have a one question that is 'how to make box of output ?', whenever you run the cell and coming output in box but in my situation its not happend.

  • codebasics
    December 2, 2020

    In spite of doing wrap text & merge & centre to my column headings Price & Price to Earning Ratio, I am getting unnamed columns, why? 🙁

  • codebasics
    December 2, 2020

    But why "Unnamed: 0_level_0" is appearing even though it is not exist in the excel sheet

  • codebasics
    December 2, 2020

    That was very helpful

  • codebasics
    December 2, 2020

    thank you sir for valuble classes

  • codebasics
    December 2, 2020

    Your teaching style is supper

  • codebasics
    December 2, 2020

    Thanku so much sir

  • codebasics
    December 2, 2020

    Hi how to pivot multiple columns in python pandas? For example I have 9 columns and I want to retain columns 1 to 3 and pivot the columns from 4 to 9.

  • codebasics
    December 2, 2020

    Machine learning tutorials with exercises are available at:
    https://www.youtube.com/watch?v=gmvvaobm7eQ&list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw

  • codebasics
    December 2, 2020

    To get rid of "Unnamed: 0_level_0" in a column:
    df = pd.read_excel('./stocks.xlsx', header=[0,1], index_col=[0])

  • codebasics
    December 2, 2020

    thanks sir….best way to giving training

  • codebasics
    December 2, 2020

    What would be the difference between…
    𝚍𝚏 = 𝚙𝚍.𝚛𝚎𝚊𝚍_𝚎𝚡𝚌𝚎𝚕(𝚏𝚒𝚕𝚎𝚗𝚊𝚖𝚎.𝚡𝚕𝚜𝚡, 𝚑𝚎𝚊𝚍𝚎𝚛= [𝟶,𝟷,𝟸])

    𝚍𝚏 = 𝚙𝚍.𝙳𝚊𝚝𝚊𝙵𝚛𝚊𝚖𝚎(𝚍𝚏)

    𝚙𝚛𝚒𝚗𝚝(𝚍𝚏)

    And this…

    𝚍𝚏 = 𝚙𝚍.𝚛𝚎𝚊𝚍_𝚎𝚡𝚌𝚎𝚕(𝚏𝚒𝚕𝚎𝚗𝚊𝚖𝚎.𝚡𝚕𝚜𝚡, 𝚑𝚎𝚊𝚍𝚎𝚛= [𝟶,𝟷,𝟸])

    𝚙𝚛𝚒𝚗𝚝(𝚍𝚏)

  • codebasics
    December 2, 2020

    my first row is showing two times please check this screenshot :

    http://prntscr.com/mfalyx

    i wrote first row one time please check screenshot of my excel file too:

    http://prntscr.com/mfamh0

    and screenshot of my code is below:
    http://prntscr.com/mfan0m

  • codebasics
    December 2, 2020

    thanks

  • codebasics
    December 2, 2020

    I had a whole column with string input, it does not show that in the df.stack() output. Why does it leave the entire row ?
    Somebody plz help.

  • codebasics
    December 2, 2020

    Excellent

  • codebasics
    December 2, 2020

    sir what is the meaning of header=[0,1]…… if we use header=0 which skips first row treats second row as header.. and how to access that dataframe…

  • codebasics
    December 2, 2020

    Hi , can you please provide some practice questions as well so we can solve those problems to do hands-on . Really liked your videos.

  • codebasics
    December 2, 2020

    i beg you sir please tell about Web Crawler and how to make it in simple step

Write a comment