Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Pandas index objects

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how Pandas index objects". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "how Pandas index objects" together.

set_index

DataFrame can set single index and compound index through set_index method.

DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False)

append Add a new index, drop is False and inplace is True, the index reverts to a column

In [307]: dataOut[307]: a b c d0 bar one z 1.01 bar two y 2.02 foo one x 3.03 foo two w 4.0In [308]: indexed1 = data.set_index('c')In [309]: indexed1Out[309]: a b dc z bar one 1.0y bar two 2.0x foo one 3.0w foo two 4.0In [310]: indexed2 = data.set_index(['a', 'b'])In [311]: indexed2Out[311]: c da b bar one z 1.0two y 2.0foo one x 3.0two w 4.0reset_index

reset_index can restore the index from the default integer index

DataFrame.reset_index(level=None, drop=False, inplace=False, col_level=0, col_fill=")

level controls the index of the level to be restored

drop False Index columns are reverted to normal columns, otherwise they are lost

In [318]: dataOut[318]: c da b bar one z 1.0two y 2.0foo one x 3.0two w 4.0In [319]: data.reset_index()Out[319]: a b c d0 bar one z 1.01 bar two y 2.02 foo one x 3.03 foo two w 4.0 Thank you for reading, the above is the content of "Pandas how to index objects", after learning this article, I believe everyone has a deeper understanding of Pandas how to index objects, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report