Python读取txt文件,有两种方式: (1)逐行读取 data=open("data.txt") line=data.readline() while line: print line line=data.readline() (2)一次全部读入内存 data=open("data.txt") for line in data.readlines(): print line
# 'C:\Users\SAM\Desktop\数据竞赛\个人征信_1108\个人征信\train\bank_detail_train.txt'# 反斜杠的写法会报编码错误f=open('C:/Users/SAM/Desktop/数据竞赛/个人征信_1108/个人征信/train/bank_detail_train.txt')result= []iter_f=iter(f) #用迭代器循环访问文件中的每一行for line in iter_f: result.append(line)f.clos
方法和画折线图类似,差别在于画图函数不一样,用的是scatter() import matplotlib.pyplot as plt #以外部两个txt表分别作为x,y画图n=0m=0with open(r'C:\Users\Administrator\Desktop\test.txt') as text: a=text.readlines()with open(r'C:\Users\Administrator\Desktop\tet.txt') as tet: month=tet.