解决FileNotFoundError: [Errno 2] No such file or directory: ‘220102933.86_56.csv‘

**

解决FileNotFoundError: [Errno 2] No such file or directory: ‘220102933.86_56.csv’

**
代码如下

import csv
import os
import pandas as pd

# 先创建一个空列表,然后通过for循环实现
readList = []
files = os.listdir(r"D:\Lynn.Yan\Python\Plot\data")

# i是文件
# 读取多个csv文件内容
# 跳过第一行“标题”
# 添加“文件名”作为新的列
for i in files:
    with open('{}'.format(i), 'r') as read_csvfile:
        read_all = csv.reader(read_csvfile)
        next(read_csvfile)
        for line in read_all:
            line.append(i)
            readList.append(line)

# list转化成dataframe
# 添加列名
testData = pd.DataFrame(readList)
titleList = ["Cycle", "Voltage", "Current", "RPM", "Torque", "Force", "Position",
             "CustomAI", "TC1", "TC2", "TC3", "TC4", "TC5", "UpdateTime", "Filename"]
testData.columns = titleList
testData.head()

查找不到某文件时,检查项目路径上是否有该文件,files是读取文件名,该路径需要保留你要读取的文件,for循环是根据运行文件路径也要保存你要查找文件。
解决FileNotFoundError: [Errno 2] No such file or directory: ‘220102933.86_56.csv‘_第1张图片
解决FileNotFoundError: [Errno 2] No such file or directory: ‘220102933.86_56.csv‘_第2张图片

你可能感兴趣的:(python,pandas,开发语言)