df.at what can it do for me
时间: 2024-03-24 17:39:28 浏览: 10
`df.at` is a method in pandas library of Python, which allows you to access a single value in a DataFrame based on its label.
You can use `df.at` to set or get a single value in a DataFrame at a specified row and column label. For example:
```python
import pandas as pd
# create a DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]}, index=['row1', 'row2', 'row3'])
# get the value at row2 and column 'B'
value = df.at['row2', 'B']
print(value) # Output: 5
# set the value at row1 and column 'C'
df.at['row1', 'C'] = 10
print(df)
```
In the example above, `df.at['row2', 'B']` gets the value at row2 and column 'B', which is 5. `df.at['row1', 'C'] = 10` sets the value at row1 and column 'C' to 10.