fix append error and decimal regex

This commit is contained in:
Pritimay Sarkar
2024-02-19 12:04:46 +05:30
parent 3c599dd727
commit 439efbc1c9
2 changed files with 14 additions and 14 deletions

View File

@@ -184,12 +184,12 @@ def performance(request):
def extract_numbers(s):
if "HB" in s:
match = re.search(r'-(\d+)$', s)
match = re.search(r'-([\d.]+)$', s)
else:
match = re.search(r'-(\d+)', s) or re.search(r'(\d+)', s)
match = re.search(r'-([\d.]+)', s) or re.search(r'([\d.]+)', s)
if match:
return int(match.group(1))
return float(match.group(1))
else:
return None

View File

@@ -74,25 +74,25 @@ df_reference_device = pd.DataFrame(denovix_reference_values).T
df_reference_device.index.name = 'Solution'
df_reference_device.columns.name = 'Wavelength'
df = pd.read_excel(curdir + path_delim + "data" + path_delim + "data_06_12_2023_12_47.xlsx", sheet_name="data")
df = pd.read_excel(curdir + path_delim + "data" + path_delim + "data_19_02_2024_05_58.xlsx", sheet_name="data")
if not df.empty:
conditions = [df['name'].str.contains('Tar', case=False, na=False),
df['name'].str.contains('KM', case=False, na=False),
conditions = [df['name'].str.contains('Tartrazine', case=False, na=False),
df['name'].str.contains('Acid Red', case=False, na=False),
df['name'].str.contains('HB', case=False, na=False)]
choices = ['Tartrazine', 'KMnO4', "HB"]
choices = ['Tartrazine', 'Acid Red', "HB"]
df['solution'] = np.select(conditions, choices, default=None)
def extract_numbers(s):
if "HB" in s:
match = re.search(r'-(\d+)$', s)
match = re.search(r'-([\d.]+)$', s)
else:
match = re.search(r'-(\d+)', s) or re.search(r'(\d+)', s)
match = re.search(r'-([\d.]+)', s) or re.search(r'([\d.]+)', s)
if match:
return int(match.group(1))
return float(match.group(1))
else:
return None
@@ -195,7 +195,7 @@ if not df.empty:
fig, ax = plt.subplots()
filtered_df = df[df['solution'].isin(['KMnO4', 'Tartrazine', 'HB'])]
filtered_df = df[df['solution'].isin(['Acid Red', 'Tartrazine', 'HB'])]
for solution in filtered_df['solution'].unique():
if pd.notna(solution):
@@ -224,7 +224,7 @@ if not df.empty:
wks1.write(row, 3, str(r_value**2))
# Add the linear fit results to the new DataFrame
df_linearfit_results = df_linearfit_results.append({'Solution': solution, 'Slope': slope, 'Intercept': intercept, 'R^2': r_value**2}, ignore_index=True)
df_linearfit_results = df_linearfit_results._append({'Solution': solution, 'Slope': slope, 'Intercept': intercept, 'R^2': r_value**2}, ignore_index=True)
row += 1