直接上代码: # 读文件 def get_venue(file): fname = file # 文件名 # 获取数据长度 len = 0 with open(fname, 'r+', encoding='utf-8') as f: for line in f.readlines(): len += 1 # 创建数组,并赋值 list = [[None] * len for i in range(2)] i = 0 with open(fname, 'r+', encoding='utf-8')
datafile.txt #文件 Man: this is the right room for an argument. Other Man: I've told you once. Man: No you haven't Other Man: Yes, I have. (pause) Man: When? Other Man: Just now. Man: No you didn't Other Man: Yes I did. Man: You didn't Other Man: I'm
我们在用python进行数据处理时往往需要将文件中的数据取出来做一些处理,这时我们应该注意数据文件的路径.文件路径不对,回报如下错误: FileNotFoundError: File b'..Advertising.csv' does not exist 这里列举几种常见的文件路径 1.当文件在当前目录下时:直接用单引号文件名 import numpy as nppath='testdata.csv'data=np.read_csv(path) 2.文件在上一级目录时:大家注意windows读取