File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -41,12 +41,24 @@ def create_widgets(self):
41
41
self .plot_button .pack (pady = 10 )
42
42
43
43
def load_csv (self ):
44
- # Open file dialog to select a CSV file
45
44
self .filename = filedialog .askopenfilename (filetypes = [("CSV files" , "*.csv" )])
46
45
if self .filename :
47
46
try :
48
- # Read file with pandas
49
- self .data = pd .read_csv (self .filename )
47
+ with open (self .filename , "r" , encoding = "utf-8" ) as f :
48
+ lines = f .readlines ()
49
+
50
+ header_index = None # Find the row where 'Counter' appears
51
+ for i , line in enumerate (lines ):
52
+ if "Counter" in line :
53
+ header_index = i
54
+ break
55
+
56
+ if header_index is None :
57
+ messagebox .showerror ("Error" , "CSV file must contain a 'Counter' column." )
58
+ return
59
+
60
+ # Now read CSV again, skipping metadata lines before the header
61
+ self .data = pd .read_csv (self .filename , skiprows = header_index , header = 0 )
50
62
51
63
# Ensure 'Counter' column is present
52
64
if 'Counter' not in self .data .columns :
You can’t perform that action at this time.
0 commit comments