![](/img/trans.png)
[英]How can I remove a row from csv file with python where a value of any column is missing
[英]How can I turn csv file row column value into (row, column, value) in Python
01 02 03
01 | 11 | 22 | 33 |
02 | 44 | 55 | 66 |
03 | 77 | 88 | 99 |
→ (row, column, value)
→ (01, 01, 11)
→ (01, 02, 22)
→ (01, 03, 33)
→ (02, 01, 44)
我想通過數組或for循環使用python ~~
這樣〜
for x in range(len(row))
假設您有如下的example.csv文件:
11|22|33
44|55|66
77|88|99
with open("example.csv") as handler:
for r,l in enumerate(handler):
for col, e in enumerate(l.split('|')):
print('row: %s, col %s, value: %s' % (r+1, col+1, e))
with open("t.csv","rb") as open_file:#Read the file
my_file = open_file.read().decode('utf-8','ignore')
data = my_file.splitlines()
data = [r.split('|') for r in data]
row_len = len(data)
for i,j in enumerate(data):
col_len = len(data[0])
start_index = 0
while start_index<col_len:
print (str(i).ljust(2,'0'),str(start_index).ljust(2,'0'),str(data[i][start_index]))
start_index+=1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.