Browse Source

提取表格数据

wxz 3 weeks ago
parent
commit
20b4f9896c
1 changed files with 18 additions and 0 deletions
  1. 18 0
      data/analyze_data/analyze_xls.py

+ 18 - 0
data/analyze_data/analyze_xls.py

@@ -0,0 +1,18 @@
+import pandas as pd
+
+def readXls(path):
+    # 读取xls文件
+    df = pd.read_excel(path)
+
+    # 将第一列数据按加号分隔
+    df.iloc[:, 0] = df.iloc[:, 0].astype(str).str.split('+')
+
+    # 将DataFrame数据转换为字典列表
+    data_list = df.to_dict('records')
+
+    return data_list
+
+if __name__ == '__main__':
+    print(readXls('kv.xls'))
+
+