import numpy as np
import pandas as pd
df = pd.DataFrame({'A': 'foo bar foo bar foo bar foo foo'.split(),
'B': 'one one two three two two one three'.split(),
'C': np.arange(8), 'D': np.arange(8) * 2})
print(df)
# df1和df3拥有同样的效果,但是isin的列表里面可以含有多个数组
df1=df.loc[df['A'].isin(['foo'])]
df2=df.loc[df['B'].isin(['one','two'])]
df3=df.loc[df['A']=='foo']
df4=df.loc[~df['A'].isin(['foo'])]
df5=df.loc[df['A']!='foo']
# 可以进行排列组合"=="这个条件需要括起来
# df6=df.loc[df['A'].isin(['foo'])&(df['B']=='one')]
df6=df.loc[(df['A']=='foo') & df['B'].isin(['one','two'])]
# 把某一列设为索引,然后输出某个特定值。
df = df.set_index(['B'])
df=df.reset_index(drop=True)
print(df.loc[:,'A'])