首先构建dataframe
:
import pandas as pd
df: pd.DataFrame = pd.DataFrame([
[1, 4, 5, 4, 6],
[70, 3, 3, 8, 2],
[5, 0, 5, 4, 6]
], columns=['one', 'two', 'three', 'four', 'five'])
选取多列
选取’one’与’three’两行:
df[['one','three']]
选取’one’与’four’四列:
df.loc[:,'one':'four']
选取多行
选取1与2行(这里的1与2是index)
df.loc[[1,2],:]
选择1:3行
df.loc[[1:3],:]