Browse Source

提取表格数据

wxz 3 weeks ago
parent
commit
0b3cccb23f
1 changed files with 15 additions and 5 deletions
  1. 15 5
      data/analyze_data/analyze_xls.py

+ 15 - 5
data/analyze_data/analyze_xls.py

@@ -5,16 +5,26 @@ def readXls(path):
     df = pd.read_excel(path)
 
     # 分隔
-    df.iloc[:, 0] = df.iloc[:, 0].astype(str).str.split('+')
-    df.iloc[:, 2] = df.iloc[:, 2].astype(str).str.split('/')
-    df.iloc[:, 4] = df.iloc[:, 4].astype(str).str.split('/')
-    df.iloc[:, 6] = df.iloc[:, 6].astype(str).str.split('/')
+    num_columns = df.shape[1]
+    for col_index in range(num_columns):
+        column_data = df.iloc[:, col_index]
+        for value in column_data:
+            if "+" in str(value):
+                column_data=column_data.astype(str).str.split('+')
+                break
+            if "," in str(value):
+                column_data=column_data.astype(str).str.split(',')
+                break
+            if "/" in str(value):
+                column_data=column_data.astype(str).str.split('/')
+                break
+        df.iloc[:, col_index]=column_data
 
     # 将DataFrame数据转换为字典列表
     data_list = df.to_dict('records')
-
     return data_list
 
 
 
 
+