ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Redgrave/McDonaldsCsvSearch.py
Revision: 792
Committed: Fri Sep 8 15:03:44 2023 UTC (2 years, 6 months ago) by nino.borges
Content type: text/x-python
File size: 2271 byte(s)
Log Message:
A simple program that will read a CSV and perform searches, exporting results and a report

File Contents

# Content
1 """
2
3 McDonaldsCsvSearch
4
5 Created by:
6 Emanuel Borges
7 11.03.2022
8
9 A simple program that will read a CSV and perform searches, exporting results and a report.
10 NOTE: using the csv library since this data has newline characters and delimiter characters inside of the cells.
11 Also, the hits compute the number of rows wiht hits and the number of cells (with a tie back to the row) of hits. I'm asking if the cell contains the value and not
12 how many times does the value show up in that cell.
13 """
14
15 import csv, os
16
17 if __name__ == '__main__':
18 csvFileName = r"C:\Users\eborges\Documents\Cases\McDonalds\McDonald_s - Attachment 2 to Creative Approval Disposition Memo (2022) - USE THIS ONE(6579111.2).csv"
19 ## Must be uppercase here.
20 searchTerm = 'PACKAG'
21
22 outputFileName = r"C:\Users\eborges\Documents\Cases\McDonalds\McDonald_s - Attachment 2 to Creative Approval Disposition Memo (2022) - EXPORTED.csv"
23 outputReportFileName = r"C:\Users\eborges\Documents\Cases\McDonalds\McDonald_s - Attachment 2 to Creative Approval Disposition Memo (2022) - REPORT.csv"
24
25
26
27 with open(csvFileName,mode='r') as csv_file:
28 csv_reader = csv.reader(csv_file, delimiter='|', quotechar = '"')
29 data = list(csv_reader)
30 headderRow = data[0]
31 headerMatrix = {}
32 for colNumber,colName in enumerate(headderRow):
33 headerMatrix[colNumber] = colName
34 row_count = len(data)
35 rowsAndColumnsList = []
36 rowsSet = set()
37 rowsDataList = []
38 for i, row in enumerate(csv_reader):
39 for j, column in enumerate(row):
40 if searchTerm in column.upper():
41 rowsAndColumnsList.append((i,j))
42 rowsSet.add(i)
43 ## NOTE that I need to change this to a csv, using the csv lib, since it probably wont parse this way due to delimiter issues.
44 rowsDataList.append(row)
45 print("There are %s rows in this file."% str(row_count))
46 print("There are %s cells that have this term."% str(len(rowsAndColumnsList)))
47 print("There are %s rows that have this term."% str(len(rowsSet)))
48 print("Here is the term report breakdown:")
49 print("-"*20)
50