Oliviayc commited on
Commit
d8b957c
·
1 Parent(s): 7b4f086

create new function to proceed column name in CSV file

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -13,6 +13,17 @@ nlp = spacy.load("en_core_web_md")
13
  st.title("Scattertext Analysis")
14
  st.header("Put your file here... ")
15
 
 
 
 
 
 
 
 
 
 
 
 
16
  def compatison1(selected_column):
17
  # type_of_comparison 1
18
  row2_col1, row2_col2 = st.columns(2)
@@ -99,7 +110,7 @@ if __name__ == '__main__':
99
  df = pd.read_csv(uploaded_file)
100
  abstract_col = 'Abstract'
101
  title_col = 'Title'
102
- source_title_col = 'Source title'
103
  year_col = 'Year'
104
  # preview the uploaded file
105
  elif uploaded_file.name.endswith(".txt"):
 
13
  st.title("Scattertext Analysis")
14
  st.header("Put your file here... ")
15
 
16
+ def find_column_name(df, column_hint):
17
+ """
18
+ Searches through the DataFrame columns to find a match for a hint provided,
19
+ ignoring case and whitespace differences.
20
+ """
21
+ column_hint = column_hint.lower().replace(' ', '')
22
+ for col in df.columns:
23
+ if col.lower().replace(' ', '') == column_hint:
24
+ return col
25
+ raise ValueError(f"Column matching '{column_hint}' not found.")
26
+
27
  def compatison1(selected_column):
28
  # type_of_comparison 1
29
  row2_col1, row2_col2 = st.columns(2)
 
110
  df = pd.read_csv(uploaded_file)
111
  abstract_col = 'Abstract'
112
  title_col = 'Title'
113
+ source_title_col = find_column_name(df, 'Source Title')
114
  year_col = 'Year'
115
  # preview the uploaded file
116
  elif uploaded_file.name.endswith(".txt"):