pandas.DataFrame.setitem¶
Set data to a DataFrame by indexer.
Limitations¶
Supported setting a column in a DataFrame through private method
df._set_column(key, value)
.- DataFrame passed into jit region as a parameter is not changed outside of the region.
New DataFrame should be returned from the region in this case.
Supported setting a column in a non-empty DataFrame as a 1D array only.
import pandas as pd
from numba import njit
@njit
def dataframe_set_new_column():
df = pd.DataFrame({'A': [-2., -1., 0., 1., 2.],
'C': [0, 1, 2, 3, 4]})
return df._set_column('B', [-1., 1., 0., 0.1, -0.1])
print(dataframe_set_new_column())
$ python ./dataframe/setitem/df_set_new_column.py
A C B
0 -2.0 0 -1.0
1 -1.0 1 1.0
2 0.0 2 0.0
3 1.0 3 0.1
4 2.0 4 -0.1
import pandas as pd
from numba import njit
@njit
def dataframe_set_existing_column():
df = pd.DataFrame({'A': [-2., -1., 0., 1., 2.],
'B': [2., 1., 0., -1., -2.],
'C': [0, 1, 2, 3, 4]})
return df._set_column('B', [-1., 1., 0., 0.1, -0.1])
print(dataframe_set_existing_column())
$ python ./dataframe/setitem/df_set_existing_column.py
A B C
0 -2.0 -1.0 0
1 -1.0 1.0 1
2 0.0 0.0 2
3 1.0 0.1 3
4 2.0 -0.1 4
See also
- Series.getitem
Get value(s) of Series by key.
- Series.setitem
Set value to Series by index
- Series.loc
Access a group of rows and columns by label(s) or a boolean array.
- Series.iloc
Purely integer-location based indexing for selection by position.
- Series.at
Access a single value for a row/column label pair.
- Series.iat
Access a single value for a row/column pair by integer position.
- DataFrame.getitem
Set value to DataFrame by index
- DataFrame.loc
Access a group of rows and columns by label(s) or a boolean array.
- DataFrame.iloc
Purely integer-location based indexing for selection by position.
- DataFrame.at
Access a single value for a row/column label pair.
- DataFrame.iat
Access a single value for a row/column pair by integer position.