File size: 2,121 Bytes
a31ba66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import csv
from collections import Counter

# Initialize Counter object to keep track of the frequency of each topic
topic_counter = Counter()
include_positive = False
interested_topics = ["none", "error", "issue", "high cpu utilization", "lambdas", "authentication issue",
                     "error message"]
summary_list = []
topic_summary_list = {}
# Read the CSV file
try:
    with open('csv/platform-engg-updated.csv', 'r', newline='', encoding='utf-8') as csvfile:
        csv_reader = csv.DictReader(csvfile)

        for row in csv_reader:
            # Extract the Positive Topics and Negative Topics fields and evaluate them as Python lists
            positive_topics = eval(row['Positive Topics'])
            negative_topics = eval(row['Negative Topics'])

            # Update the counter based on the topics in this row

            if include_positive:
                for topic in positive_topics:
                    topic_counter[topic.lower()] += 1

            for topic in negative_topics:
                topic_counter[topic.lower()] += 1
                if topic.lower() in interested_topics:
                    summary_list.append(row['Summary'])
                    if topic.lower() in topic_summary_list:
                        topic_summary_list[topic.lower()].append(row['Summary'])
                    else:
                        topic_summary_list[topic.lower()] = [row['Summary']]

    # Display the consolidated list of topics along with their frequency
    print(f"Consolidated List of Topics with Frequency({len(topic_counter.items())}):")
    for topic, freq in topic_counter.most_common():
        print(f"{topic}, {freq}")
    print("Short listed summaries:")
    for topic in topic_summary_list:
        print(f"-------------------{topic}-------------------------------" )
        for summary in topic_summary_list[topic]:
            print(summary)
            print("  ")
except FileNotFoundError:
    print("File not found. Please make sure the file 'your_file.csv' exists in the same directory as this script.")
except Exception as e:
    print(f"An error occurred: {e}")