import csv
import numpy as np
with open("D:\PHD\obranking\\cell_split_demo.csv", mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
print(csv_reader.fieldnames)
col_count = print(len(csv_reader.fieldnames))
#print(sum(1 for row in csv_file))
row_count = 0
for line in enumerate(csv_reader):
print(line[csv_reader.fieldnames[1]])
@peter Otten this above one is Test10.py
@peter otten below i am posting how i created cell_split_demo.csv using test9.py
this is test9.py
import csv
import numpy as np
with open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file1,
open("D:\PHD\obranking\\demo.csv", mode='r') as csv_file2:
csv_reader1 = csv.DictReader(csv_file1)
csv_reader2 = csv.DictReader(csv_file2)
#csv_contents = list(csv_reader)
#for i in csv_contents:
#print(i['label'])
#print(csv_contents)
filename = "cell_split_demo.csv"
with open("D:\PHD\obranking\\cell_split_demo.csv", 'w') as csvfilew1:
fields = (range(0, 300))
csvwriter1 = csv.DictWriter(csvfilew1, fieldnames=fields)
csvwriter1.writeheader()
for i, row in enumerate(csv_reader1):
Mat = np.full([1, 300], '', dtype='object')
matrixrows = dict().fromkeys(fields)
for j, line in enumerate(csv_reader2):
if j != 300:
matrixrows[j] = []
if row['label'] != line['label']:
for k in range(1,5502):
if row[csv_reader1.fieldnames[k]] !=
line[csv_reader2.fieldnames[k]]:
if Mat[0][j] == '':
Mat[0][j] = str(k)
else:
Mat[0][j] += '#' + str(k)
#print(Mat[0][j])
print(i)
#print(j)
matrixrows[j].append(Mat[0][j])
if j == 299:
csvwriter1.writerow(matrixrows)
csv_file2.seek(0)
--
https://mail.python.org/mailman/listinfo/python-list