python - 如何更改 Pandas 系列中的单个值?
问题描述
import pandas as pd
test_df = pd.Series([0,0,0,1,1,1,1,0,1,1,1,1])
test_df[0] = 1
如何将此系列中的第一个值更改为一个?它不像列表那样工作。我尝试使用 .replace 方法,但我只想更改一个值,而不是全部。
解决方案
尝试loc
test_df.loc[0] = 1
test_df
Out[140]:
0 1
1 0
2 0
3 1
4 1
5 1
6 1
7 0
8 1
9 1
10 1
11 1
dtype: int64
推荐阅读
- flutter - Flutter bloc:更新状态不会重新调用 BlocBuilder
- java - 如何将javafx默认警报框错误图标对齐到右侧?
- c# - 如何将应用程序设置绑定到 TableView 中已编辑的 EntryCell?
- css - 需要在选项卡中标准呈现单选按钮和标签的纯 CSS 选项卡
- sql - 如何在 Hive sql 中用一个替换 3 个相同的字符?
- javascript - Highcharts 导出到 zip
- javascript - Vue.js 销毁在组件内运行的 setInterval
- xslt - 跨嵌套元素的 XSLT 重复数据删除
- docker - Docker 服务不会在容器内运行 - 错误:ulimit:错误设置限制(不允许操作)
- c++ - SetFont() 函数不适用于 wxFrame