insert single value in dataframe using index 1

insert single value in dataframe using index

>>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]],
               index=[4, 5, 6], columns=['A', 'B', 'C'])
>>> df.at[4,'B']
2
>>> df.at[4,'B'] = 10
>>> df.at[4,'B']
10

Here is what the above code is Doing:
1. Create a DataFrame with 3 rows and 3 columns.
2. Set the index of the DataFrame to be [4, 5, 6].
3. Set the column names of the DataFrame to be [‘A’, ‘B’, ‘C’].
4. Access the value at row 4 and column ‘B’.
5. Set the value at row 4 and column ‘B’ to be 10.
6. Access the value at row 4 and column ‘B’ again.

Similar Posts