- Python:Data Analytics and Visualization
- Phuong Vo.T.H Martin Czygan Ashish Kumar Kirthi Raman
- 275字
- 2021-07-09 18:51:39
Indexing and selecting data
In this section, we will focus on how to get, set, or slice subsets of Pandas data structure objects. As we learned in previous sections, Series or DataFrame objects have axis labeling information. This information can be used to identify items that we want to select or assign a new value to in the object:
>>> s4[['024', '002']] # selecting data of Series object 024 NaN 002 Mary dtype: object >>> s4[['024', '002']] = 'unknown' # assigning data >>> s4 024 unknown 065 NaN 002 unknown 001 Nam dtype: object
If the data object is a DataFrame structure, we can also proceed in a similar way:
>>> df5[['b', 'c']] b c 0 1 2 1 4 5 2 7 8
For label indexing on the rows of DataFrame, we use the ix
function that enables us to select a set of rows and columns in the object. There are two parameters that we need to specify: the row
and column
labels that we want to get. By default, if we do not specify the selected column names, the function will return selected rows with all columns in the object:
>>> df5.ix[0] a 0 b 1 c 2 Name: 0, dtype: int64 >>> df5.ix[0, 1:3] b 1 c 2 Name: 0, dtype: int64
Moreover, we have many ways to select and edit data contained in a Pandas object. We summarize these functions in the following table:

Tip
Pandas data objects may contain duplicate indices. In this case, when we get or set a data value via index label, it will affect all rows or columns that have the same selected index name.
- Java開發(fā)技術(shù)全程指南
- Multimedia Programming with Pure Data
- 可編程控制器技術(shù)應(yīng)用(西門子S7系列)
- 計(jì)算機(jī)系統(tǒng)結(jié)構(gòu)
- 數(shù)據(jù)庫系統(tǒng)原理及應(yīng)用教程(第5版)
- Red Hat Linux 9實(shí)務(wù)自學(xué)手冊(cè)
- Photoshop CS4數(shù)碼攝影處理50例
- 無人駕駛感知智能
- 深度學(xué)習(xí)原理與 TensorFlow實(shí)踐
- 人工智能:智能人機(jī)交互
- 電腦故障排除與維護(hù)終極技巧金典
- 西門子S7-1200/1500 PLC從入門到精通
- Microsoft System Center Data Protection Manager Cookbook
- 軟件質(zhì)量管理實(shí)踐
- 當(dāng)產(chǎn)品經(jīng)理遇到人工智能