# pandas.Series.setitem¶

Set value to Series by index

## Limitations¶

Not supported for idx as a string slice, e.g. S[‘a’:’f’] = value

Not supported for string series

Not supported for a case of setting value for non existing index

Not supported for cases when setting causes change of the Series dtype

## Examples¶

```
import numpy as np
import pandas as pd
from numba import njit
@njit
def series_setitem():
value = 0
series = pd.Series(np.arange(5, 0, -1)) # Series of 5, 4, 3, 2, 1
series[0] = value
return series # result Series of 0, 4, 3, 2, 1
print(series_setitem())
```

```
$ python ./series/series_setitem_int.py
0 0
1 4
2 3
3 2
4 1
dtype: int64
```

```
import numpy as np
import pandas as pd
from numba import njit
@njit
def series_setitem():
value = 0
series = pd.Series(np.arange(5, 0, -1)) # Series of 5, 4, 3, 2, 1
series[2:5] = value
return series # result Series of 5, 4, 0, 0, 0
print(series_setitem())
```

```
$ python ./series/series_setitem_slice.py
0 5
1 4
2 0
3 0
4 0
dtype: int64
```

```
import numpy as np
import pandas as pd
from numba import njit
@njit
def series_setitem():
value = 0
series = pd.Series(np.arange(5, 0, -1)) # Series of 5, 4, 3, 2, 1
indices = pd.Series(np.asarray([1, 3]))
series[indices] = value
return series # result Series of 5, 0, 3, 0, 1
print(series_setitem())
```

```
$ python ./series/series_setitem_series.py
0 5
1 0
2 3
3 0
4 1
dtype: int64
```

See also

- Series.getitem
Get value(s) of Series by key.

- 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
Get data from a DataFrame by indexer.

- DataFrame.setitem
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.