python中有关文件的知识。
1、文件的读取
调用open()函数,返回一个File对象; fp = open('D:/123/Test.txt', 'w')
调用File对象的read()或write()方法; fp.write('HelloWorld')
# -*- coding: utf-8 -*-
"""
Created on Mon May 6 11:08:37 2019
@author: 小米
"""
import pandas as pd
def ExcelToCsv_1(StartName, SheetName, EndName):
grade = pd.read_excel(StartName, sheet_name=SheetName)
for i in range(len(grade.index)):
for j in range(1, len(grade.columns)):
if grade.iloc[i, j] == '优秀':
grade.iat[i, j] = 90
elif grade.iloc[i, j] == '良好':
grade.iat[i, j] = 80
elif grade.iloc[i, j] == '合格':
grade.iat[i, j] = 60
else:
grade.iat[i, j] = 0
grade.to_csv(EndName)
def ExcelToCsv_2(StartName, SheetName, EndName):
grade = pd.read_excel(StartName, sheet_name=SheetName)
Grade = grade.replace("优秀", "90")
Grade = Grade.replace("良好", "80")
Grade = Grade.replace("不合格", "60")
Grade = Grade.replace("合格", "60")
Grade = Grade.fillna(value = 0)
Grade.to_csv(EndName)
ExcelToCsv_2('D:/Users/小米/Desktop/Python成绩登记信计.xlsx', 'Sheet1', 'D:/Users/小米/Desktop/Python成绩登记信计.csv')
ExcelToCsv_1('D:/Users/小米/Desktop/Python成绩.xlsx','Sheet2' ,'D:/Users/小米/Desktop/Python成绩.csv')
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步