new = pd.read_excel(file_path,engine='openpyxl',dtype=str)
有时候dype不知道为什么会失效,那就再加一个
new = new.astype(str)
如果表格中有很多sheet,那么再添加一个参数sheet_name='sheet的名字'
表格转列表
new_= pd.read_excel(file_path,engine='openpyxl',sheet_name='人',dtype=str) new_ = new_.astype(str)#读入 tag_ = new_.columns.to_list()#列名保存 print('保存下来的列名:',tag_) new = np.array(new_).tolist()#转为列表待处理
简而言之就是先把列名存下来,
然后再对表先进行np.array,再tolist()就可以了,这样转换成的列表形式是[[],[],[]]的形式,其中每一个里面最小的中括号表示的都是一行数据。
列表转csv的保存方式:
a = pd.DataFrame(columns=列名, data=其他行) a.to_csv(file_path[:-5]+".tagged.csv")
如果不想要行标签,那么就加一个参数index=None