Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 93 characters in body
Source Link
Abhishek Patel
  • 615
  • 2
  • 10
  • 27

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",") reader2 = csv.reader(f2, delimiter=",") for line in enumerate(reader1): f.append(line) #For the first file, add them all for line in enumerate(reader2): if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line) for e in f: if any(e[0] == line[0]:  changedindexes = i != j for ei, j in fzip(e[0], line[0]):   #Line that was overwritten and changed will be printed for val in changedindexes: print (line) e[val] = e[val] + 'c' c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line) #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",") reader2 = csv.reader(f2, delimiter=",") for line in enumerate(reader1): f.append(line) #For the first file, add them all for line in enumerate(reader2): if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line) if any(e[0] == line[0] for e in f): #Line that was overwritten and changed will be printed print (line) c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line) #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",") reader2 = csv.reader(f2, delimiter=",") for line in enumerate(reader1): f.append(line) #For the first file, add them all for line in enumerate(reader2): if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line) for e in f: if e[0] == line[0]:  changedindexes = i != j for i, j in zip(e[0], line[0])    for val in changedindexes:  e[val] = e[val] + 'c' c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line) #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

added 157 characters in body
Source Link
Abhishek Patel
  • 615
  • 2
  • 10
  • 27

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",") reader2 = csv.reader(f2, delimiter=",") for line in enumerate(reader1): f.append(line) #For the first file, add them all for line in enumerate(reader2): if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line)  if any(e[0] == line[0] for e in f): #Line that was overwritten and changed will be printed print (line) c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line) #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",") reader2 = csv.reader(f2, delimiter=",") for line in enumerate(reader1): f.append(line) #For the first file, add them all for line in enumerate(reader2): if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line) c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line) #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",") reader2 = csv.reader(f2, delimiter=",") for line in enumerate(reader1): f.append(line) #For the first file, add them all for line in enumerate(reader2): if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line)  if any(e[0] == line[0] for e in f): #Line that was overwritten and changed will be printed print (line) c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line) #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

added 501 characters in body; added 60 characters in body
Source Link
Abhishek Patel
  • 615
  • 2
  • 10
  • 27

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

fromimport collectionscsv f import= OrderedDict[] importf3 csv= file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: csv1reader1 = csv.reader(f1, delimiter=",")  csv2reader2 = csv.reader(f2, delimiter=",") t1 = OrderedDict for line in enumerate(rowreader1): f.append(line)  #For the first file, add them all for rowline in csv1enumerate(reader2): t2 if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line) c3 = OrderedDictcsv.writer(rowf3, , quoting=csv.QUOTE_ALL) for rowline in csv2f: #Write the new merged files into another csv c3.writerow(line)   #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

from collections import OrderedDict import csv with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: csv1 = csv.reader(f1) csv2 = csv.reader(f2) t1 = OrderedDict(row for row in csv1) t2 = OrderedDict(row for row in csv2) #Then find the differences between the two orderedDicts 

This can be done simply by using python's built in CSV library. If you also care about the order of your entries, you can use an OrderedDict to maintain the original file order.

import csv f = [] f3 = file('results.csv', 'w') with open('file1.csv', 'rb') as f1, open('file2.csv', 'rb') as f2: reader1 = csv.reader(f1, delimiter=",")  reader2 = csv.reader(f2, delimiter=",")  for line in enumerate(reader1): f.append(line)  #For the first file, add them all for line in enumerate(reader2):  if not any(e[0] == line[0] for e in f): #For the second file, only add them if there is not an entry with the same name already f.append(line) c3 = csv.writer(f3, , quoting=csv.QUOTE_ALL) for line in f: #Write the new merged files into another csv c3.writerow(line)   #Then find the differences between the two orderedDicts 

As for bolding, there is no way to do that in CSV, as csv files contain data, not any formatting information.

Source Link
Abhishek Patel
  • 615
  • 2
  • 10
  • 27
Loading