Reader small image

You're reading from  Mastering pandas. - Second Edition

Product typeBook
Published inOct 2019
Reading LevelIntermediate
Publisher
ISBN-139781789343236
Edition2nd Edition
Languages
Tools
Right arrow
Author (1)
Ashish Kumar
Ashish Kumar
author image
Ashish Kumar

Ashish Kumar is a seasoned data science professional, a publisher author and a thought leader in the field of data science and machine learning. An IIT Madras graduate and a Young India Fellow, he has around 7 years of experience in implementing and deploying data science and machine learning solutions for challenging industry problems in both hands-on and leadership roles. Natural Language Procession, IoT Analytics, R Shiny product development, Ensemble ML methods etc. are his core areas of expertise. He is fluent in Python and R and teaches a popular ML course at Simplilearn. When not crunching data, Ashish sneaks off to the next hip beach around and enjoys the company of his Kindle. He also trains and mentors data science aspirants and fledgling start-ups.
Read more about Ashish Kumar

Right arrow

Operations on indexes

To complete this chapter, we'll discuss operations on indexes. We sometimes need to operate on indexes when we wish to realign our data or select it in different ways. There are various operations:

Note that set_index allows the creation of an index on an existing DataFrame and returns an indexed DataFrame, as we have seen before:

    In [939]: stockIndexDataDF=pd.read_csv('./stock_index_data.csv')
    In [940]: stockIndexDataDF
    Out[940]:   TradingDate  Nasdaq   S&P 500  Russell 2000
      0   2014/01/30   4123.13  1794.19  1139.36
      1   2014/01/31   4103.88  1782.59  1130.88
      2   2014/02/03   3996.96  1741.89  1094.58
      3   2014/02/04   4031.52  1755.20  1102.84
      4   2014/02/05   4011.55  1751.64  1093.59
      5   2014/02/06   4057.12  1773.43  1103.93
  

Now, we can set the index as follows:

    In [941]: stockIndexDF...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering pandas. - Second Edition
Published in: Oct 2019Publisher: ISBN-13: 9781789343236

Author (1)

author image
Ashish Kumar

Ashish Kumar is a seasoned data science professional, a publisher author and a thought leader in the field of data science and machine learning. An IIT Madras graduate and a Young India Fellow, he has around 7 years of experience in implementing and deploying data science and machine learning solutions for challenging industry problems in both hands-on and leadership roles. Natural Language Procession, IoT Analytics, R Shiny product development, Ensemble ML methods etc. are his core areas of expertise. He is fluent in Python and R and teaches a popular ML course at Simplilearn. When not crunching data, Ashish sneaks off to the next hip beach around and enjoys the company of his Kindle. He also trains and mentors data science aspirants and fledgling start-ups.
Read more about Ashish Kumar