Example Analysis of DataFrame Row and Row data filtering of pandas
Editor to share with you pandas's DataFrame row and column data screening example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
I. Cognition of DataFrame
The essence of DataFrame is row (index) column (column) index + multiple column data.
In order to simplify our understanding, we might as well change our thinking.
In reality, in order to simplify the description of a thing, we will choose several features.
For example, from the perspective of (gender, height, education, occupation, hobby, etc.) to depict a person, these "angles" are "characteristics".
Among them, different rows represent different records; columns represent characteristics, and different records vary according to the differences between each feature.
The default index of DataFrame is the serial number. Can be understood as a location index Generally speaking, we use id to identify different records and will not change the index. However, in order to understand the meaning of different features (columns), we tend to reassign column.
Some simple but not rigorous understandings are:
Ranks and ranks
Line-index-record (default index is generally used)
Column-column-feature (Custom Index)
Indexes
Default index-serial number-location-easy to index but not easy to understand
Custom Index-feature name-attribute-easy to understand
Second, filter the row and column data of dataframe.
Import pandas as pd,numpy as npfrom pandas import DataFramedf = DataFrame (np.arange (20). Reshape ((4, 5)), column = list ('abcde'))
1.df [] & df. Select column data
Df.a df [['axiajiaoyuanb']]
2.df.loc [[index], [colunm]] selects data through tags
When rows are not filtered, fill in: (cannot be empty) at [index], that is, df.loc [:,'a'] indicates that all data in column an is selected.
Df.loc [0jinjia'] df.loc [0:1, ['axiajiaoyub']] df.loc [[0pc2], [' axiajiaoyangc']]
3.df.iloc [[index], [colunm]] selects data by location
When rows are not filtered, the same as df.loc [], that is, [index] cannot be empty.
Df.iloc [0,0] df.iloc [0:1,1:3] df.iloc [[0,2], [1,3]]
4.df.ix [[index], [column]] selects data by tag or location
Df.ix [] mixes tags and location selections. It is important to note that the boxes of [index] and [column] need to specify the same type of selection.
Df.ix [[0:1], ['axiaojinjin3]] reported an error
The above is all the contents of the article "sample Analysis of pandas's DataFrame row and column data filtering". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!