"""
loc函数:基于`标签`选择数据
iloc函数:按`索引位置`选择数据
at函数:基于`标签`选择一个值
iat函数:基于`索引位置`选择一个值
"""
df['A']
df[0:3]
df['20130102':'20130104']
df.loc[dates[0]] # 2013-01-01
df.loc[:,['A','B']]
df.loc['20130102', ['A', 'B']]
df.loc['20130102':'20130104', ['A', 'B']]
df.loc[dates[0],'A']
df.iloc[3] # 整数位置选择
df.iloc[1:3, :] # 整数位置选择
df.iloc[3:5,0:2] #整数切片
df.iloc[[1, 2, 4], [0, 2]] # 整数列表按位置切片
df.iloc[:, 1:3]
df.iloc[1, 1]
# df.at[dates[0], 'A']
# df.iat[1, 1]
df[df.A>0]
df[df>0]
df1_1 = df.copy()
df1_1['E'] = ['one', 'one', 'two', 'three', 'four', 'three']
df1_1[df1_1['E'].isin(['two', 'four'])]
info_date_range = pd.date_range('20130102',periods=6)
s1 = pd.Series([1,2,3,4,5,6],index=info_date_range)
df['F'] = s1
df.at[dates[0],'A'] = 0
df.iat[0,1] = 0
df.loc[:,'D'] = np.array([5]*len(df))
df1_2 = df.copy()
# df1_2[df1_2>0] = -df1_2
df1_2
df
python pandas DataFrame数据框-【loc、iloc、at、iat标签和索引选值】
最新推荐文章于 2024-03-16 20:18:02 发布