Table of contents
Libraries required for manipulating ranks and columns
Generate the fetched dataframe object
1. Known column name access method
2. The method of accessing the location of the known column
3. The above two codes generate the same result
1. Known row name access method
2. The method of accessing the location of the known row
3. The above two codes generate the same result
(The name of the line can be obtained in the same way)
1. Known column name and row access method
2. The method of fetching the row and fetching the position of the known column
3. The above two codes generate the same result
Libraries required for manipulating ranks and columns
import pandas as pd
import numpy as np
Generate the fetched dataframe object
df=pd.DataFrame({"a":[1.78,1.8,2.8,2.75,5,5,23],"b":[20.8,10,10,30,43,1,12],"c":[23,15,50,3,343,12,95]})
print(df)
Generate result display:
dataframe fetch column
1. Known column name access method
#语法:dataframe的名字[列名]
#举例 取df的名叫a的列:
df["a"]
2. The method of accessing the location of the known column
#语法:dataframe的名字.iloc[:,第几列]
#举例 取df的第几列:
df.iloc[:,0]
3. The above two codes generate the same result
#语法:dataframe的名字[列名],或者dataframe的名字.iloc[:,第几列]
#举例 取df的名叫a的列:
df["a"]
#举例 取df的第几列:
df.iloc[:,0]
#生成结果相同
Generate result display:
dataframe fetch row
1. Known row name access method
#语法:dataframe的名字.loc[行名]
#举例,取df的行名叫0的列:
df.loc[0]
2. The method of accessing the location of the known row
#dataframe的名字[想取某行的位置:想取某行的位置+1]
#举例,取df的第0列:
df[0:1]
3. The above two codes generate the same result
#语法:dataframe的名字.loc[行名],或者dataframe的名字[想取某行的位置:想取某行的位置+1]
#举例,取df的行名叫0的列:
df.loc[0]
#举例,取df的第0列:
df[0:1]
The dataframe takes the row under the condition according to the column (column name, column position)
(The name of the line can be obtained in the same way)
1. Known column name and row access method
#语法:dataframe的名字[dataframe的名字[dataframe的列名]==该列名的值]
#举例,取df的a列值为1.78的行:
df[df["a"]== 1.78]
2. The method of fetching the row and fetching the position of the known column
#语法:dataframe的名字[dataframe的名字[dataframe的列的位置]==该列名的值]
#举例,取df的a列值为1.78的行:
df[df.iloc[:,0]==1.78]
3. The above two codes generate the same result