python对csv文件中某一列进行遍历,Python循环遍历CSV文件及其列

初学者在Python中尝试遍历CSV文件的特定列时遇到问题,代码能打开CSV文件并读取每一行,但在访问列时出现'IndexError: list index out of range'错误。解决方案指出可能是文件中没有足够的列,且建议使用`for row in reader:`来迭代行,再用`for column in row:`遍历单元格内容。
摘要由CSDN通过智能技术生成

so I've seen this done is other questions asked here but I'm still a little confused. I've been learning python3 for the last few days and figured I'd start working on a project to really get my hands dirty. I need to loop through a certain amount of CSV files and make edits to those files. I'm having trouble with going to a specific column and also for loops in python in general. I'm used to the convention (int i = 0; i < expression; i++), but in python it's a little different. Here's my code so far and I'll explain where my issue is.

import os

import csv

pathName = os.getcwd()

numFiles = []

fileNames = os.listdir(pathName)

for fileNames in fileNames:

if fileNames.endswith(".csv"):

numFiles.append(fileNames)

for i in numFiles:

file = open(os.p

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值