1.Indexing DataFrame
- Indexing using square brackets
- Using column attribute and row labels
- Using the .loc/.iloc accessor
- selecting only some columns
2. Slicing DataFrame
- 数据中某一列的数据类型是Series, Series 是有index的,介于np arrays和dict之间
- Slicing not using accessor
- Slicing using .loc/.iloc accessor
- using list rather than slices
- series versus 1-column dataframe
- Slicing rows
.loc['b':'a':-1] -1可以表示倒序;另外.loc里,此处列值部分放空也可以
3. Filtering DataFrames
- Filtering with a Boolean Series
- Combining filters
- selecting columns with all nonzeros
- selecting columns with any nonzeros
- Selecting columns with any NaNs
- Selecting columns without NaNs
- Drop rows with any NaNs
如果换成all了name就是当该行全部都是NaN才会被drop
- Filtering a column based on another
- Modifying a column based on another
salt 大于55的,egg值加5
- Filtering using NaNs:
thresh=1000表示less than 1000, axis=‘columns' 是因为axis默认是0,指的是rows
3. Transforming DataFrames
- DataFrame vectorized methods:
df.floordiv()
- numpy vectorized functions:
np.floor.divide(df,12)
- Plain python function(1)
def
plain python function(2)
- lambda function
- storing transformation
- working with string values
str.upper(): 小写转大写
- index没有apply method,用.map();
- 用两列的运算定义新的列:
- Using apply() to transform a column
用完def用apply,但好像不用apply也能做的。。。
- Using .map() with a dictionary
-
Using vectorized functions
注意导入的方式