话不多说,上去就是干,

源代码(使用的python3)

# -*- coding: utf-8 -*-
"""
Created on Sat Nov 16 14:03:26 2019


# 使用的为2018年的

list1=[此处为获取的excel中文表头];

def getIndexByValue(value,list):
all_index=[i for i, a in enumerate(list) if a == value];
if(len(all_index) > 0):
return all_index[0];
else:
return -1;
# 生成的字典对照
dictJY = {"lys20191020":"微信机器人"};


# 把list转化成json
def changeListToJson(list):
str="{";
for i,v in enumerate(list):
if((i+1)==len(list)):
str+="\"\":\""+v+"\"";
else:
str+="\"\":\""+v+"\",";

str+="}";
return str

def changeDictionaryToHiveSql(dictJY):
str="CREATE TABLE ODS_JYSJXX (";
for k,v in dictJY.items():
str+=k+" STRING COMMENT '"+v+"',\n";
str+=")";
return str


def ReNameHeaderToCSV(fileName,csvName,dictionary):
rmapping = {}
for k, v in dictJY.items():
rmapping[v] = k
import pandas as pd
xl = pd.read_excel(fileName)
xl = xl.rename(columns=rmapping)
xl.to_csv(csvName)

def changeDictionaryToSchema(dictJY):
str="";
for k,v in dictJY.items():
str+="{\"name\": \""+k+"\",\"type\": [\"string\",\"null\"]},";
return str

print(changeDictionaryToSchema(dictJY))

#ReNameHeaderToCSV('excel/2018.xlsx','2018.csv',dictJY)
#ReNameHeaderToCSV('excel/2017.xlsx','2017.csv',dictJY)