pandas.DataFrame.at#
- property DataFrame.at[源代码]#
按行/列标签对访问单个值。
与
loc类似,两者都提供基于标签的查找。如果您只需要在 DataFrame 或 Series 中获取或设置单个值,请使用at。- Raises:
- KeyError
如果获取值为 ‘label’ 并且 ‘label’ 不存在于 DataFrame 或 Series 中。
- ValueError
如果行/列标签对不是元组,或者元组中的任何标签不是 DataFrame 的标量。如果标签是类列表(不包括 NamedTuple)用于 Series。
参见
DataFrame.at通过标签访问单行/列对的单个值。
DataFrame.iat按整数位置的行/列对访问单个值。
DataFrame.loc通过标签访问一组行和列。
DataFrame.iloc通过整数位置访问行和列的组。
Series.at通过标签访问单个值。
Series.iat通过整数位置访问单个值。
Series.loc通过标签访问行的组。
Series.iloc通过整数位置访问行和列的组。
Notes
有关更多详细信息,请参阅 Fast scalar value getting and setting 。
Examples
>>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]], ... index=[4, 5, 6], columns=['A', 'B', 'C']) >>> df A B C 4 0 2 3 5 0 4 1 6 10 20 30
获取指定行/列对的值
>>> df.at[4, 'B'] 2
设置指定行/列对的值
>>> df.at[4, 'B'] = 10 >>> df.at[4, 'B'] 10
获取 Series 中的值
>>> df.loc[5].at['B'] 4