csv の 2 列目のデータをクリアする次のコード (試行) があります。
def del_col(in_path):
# read file into memory
file_obj = open(in_path, 'rb')
reader = csv.reader(file_obj, delimiter='\t')
# delete the status column here:
# Now write csv back to same file:
# write data to file
file_obj = open(in_path, 'rb')
writer = csv.writer(file_obj)
writer.writerows(data)
file_obj.close()
この列をクリアするかどうか、またはクリアする方法がわかりません。データを行ごとに読み込んで、各行の 2 番目のエントリをクリアする必要がありますか? または、2 番目の列を一度にクリアする単純な方法はありますか?
2回目の試みは次のとおりです。
def del_col(in_path):
# read file into memory
file_obj = open(in_path, 'rb')
reader = csv.reader(file_obj, delimiter='\t')
data = []
for row in reader:
# delete the status column here:
vals = [x[:1] + x[2:] for x in reader]
print vals
file_obj.close()
print 'Delete the 2nd Column (Lead Status?)'
conf = raw_input('delete these leads? (Y|N): ').upper()[0]
if conf == 'Y':
# write data to file
file_obj = open(in_path, 'wb')
writer = csv.writer(file_obj)
writer.writerows(data)
file_obj.close()