Commit 18b2b568 by Tian_zi_kang

tianzikang update: 6-zhimingqiye adapts to xlsx input

parent 1e5d8dd4
......@@ -6,7 +6,10 @@ df = pd.read_excel("知名企业.xlsx")
qiye_name = df["企业-英文名"].tolist()
file_name = "good_papers-niuren-task_10.csv"
final = pd.read_csv(file_name, encoding='utf-8-sig')
if file_name.endswith(".xlsx"):
final = pd.read_excel(file_name, engine='openpyxl')
elif file_name.endswith(".csv"):
final = pd.read_csv(file_name, encoding='utf-8-sig')
# add continent_country column
final["知名企业"] = ""
......
......@@ -223,4 +223,19 @@ def parse_name(name):
candidate_names.append(f"{last_name}, {first_name_part}")
return candidate_names
\ No newline at end of file
return candidate_names
import pandas as pd
def csv_to_xlsx(csv_file_path, xlsx_file_path):
try:
# 读取 CSV 文件
df = pd.read_csv(csv_file_path)
print(f"成功读取 CSV 文件:{csv_file_path}")
# 将数据写入 XLSX 文件
df.to_excel(xlsx_file_path, index=False, engine='openpyxl')
print(f"成功将数据写入 XLSX 文件:{xlsx_file_path}")
except Exception as e:
print(f"转换过程中发生错误:{e}")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment