import os
import pandas as pd
pathname = './data/1-27_analyze/1-16/features_marked'
file_list = [pathname + '/' + i for i in os.listdir(pathname)]
#there are only .xlsx and .csv in the directory
# tansfer .xlsx to .csv
for file in file_list:
if(file[-1] == 'v'):
pass
else: # only deal with .xlsx file
file_csv_old = file[0:-5] + '.csv'
if(os.path.exists(file_csv_old)): # remomve the csvs that already exist
os.remove(file_csv_old)
file_excel = pd.read_excel(file)
file_excel = file_excel.dropna() # to delete rows with missing values
file_excel.to_csv(file[0:-5]+'.csv', header=False, index=False, encoding='utf-8')
# transfer .csv to .xlsx
for file in file_list:
if(file[-1] == 'x'):
pass
else:
file_excel_old = file[0:-4] + '.xlsx'
if(os.path.exists(file_excel_old)):
os.remove(file_excel_old)
file_csv = pd.read_csv(file)
file_csv = file_csv.dropna()
file_csv.to_excel(file[0:-4] + '_new.xlsx', header = False, index = False, encoding = 'utf-8')
批量将excel转换为csv 2019-02-19
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 操作流程: 1. 将Excel文件保存为CSV格式 2.将CSV格式文档,鼠标右键选择打开方式:记事本中打开 3...
- 操作步骤: 1、选中需要转换的数字所在单元格,点击菜单栏【开始】(一般为默认)中的【格式】,选择【设置单元格格式】...