python - 循环遍历excel列并在python中写入新值
问题描述
我在 python 中使用 pandas,并且有一个包含一个名为 test_name 的标题的列的 excel 文件。我想遍历该列的每一行并更新值。我已经编写了从列中提取每个值的代码,但我不确定如何将新值写回单元格。
import pandas as pd
orders = pd.read_excel('test.xlsx')
if orders.columns[0] == 'test_name':
cols = [0]
test_names = pd.read_excel('test.xlsx', usecols=cols)
for name in test_names.values:
print(name[0])
new_value = 3333
#write new_value back to the current cell.
else:
print('Column test_name not found ')
解决方案
推荐阅读
- jquery - 出于安全考虑,是否有类似于 End of Life/Supported Versions 的 jQuery 版本的支持终止
- python - 哪个 Pandas 数据框更好:超长数据框 VS 结构不良的带有列表的数据框
- python - 如何在python代码中获取mnist数据集的错误接受率和错误拒绝率之间的图表
- typescript - 条件类型添加一个额外的泛型得到编译器错误
- php - 有什么具体的方法来编写 click house curl 插入查询吗?
- c - C中的单指针与双指针
- python - 如何使用 df.iterrows() 匹配同一列中的前一行值?
- rust - 请求的 Rust-rocket 匹配花费了很长时间(5 分钟)
- android - 在 Android Studio 的 build.gradle 中设置的 Android R/11 的 API 级别是什么?
- c# - C#:从集合中提取数据并将其存储在数组中