python中有关文件的知识。
Posted gsd-tt
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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‘)
以上是关于python中有关文件的知识。的主要内容,如果未能解决你的问题,请参考以下文章
你如何在 python 中处理 graphql 查询和片段?