ValueError:无效的文件路径或缓冲区对象类型:<class'tuple'=“”>

时间:2019-03-25 09:43:39

标签: file path buffer valueerror

我是一个使用python广告的初学者,尝试半自动导入YNAB。

如果我使用“ askopenfilename”并将每个csv分开,则可以使用它,但是我无法使其与askopenfilenames一起使用并在for项内循环。

然后我收到以下错误消息: ValueError:无效的文件路径或缓冲区对象类型:

附上python代码:

import pandas as pd
import numpy as np
from tkinter import filedialog
from tkinter import *
root = Tk()
root.filenames = filedialog.askopenfilenames(initialdir="C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/", title="Select file",
                                           filetypes=(("csv files", "*.csv"), ("all files", "*.*")))
print(root.filenames)
for item in root.filenames:
    print(item)
from pandas.core.tools.numeric import to_numeric
df = pd.read_csv(root.filenames, sep=';', usecols=(0, 1, 2, 3, 4),
                 encoding='utf-8', decimal=',')
df.columns = ['Date', 'Payee', 'Verwendungszweck', 'Buchungstext', 'Betrag']
df['Memo'] = df[['Buchungstext', 'Verwendungszweck']].apply(lambda x: ' -- '.join(x), axis=1)
Betrag = df.Betrag.astype(int)
df['Inflow'] = np.where(df.Betrag > 0, df.Betrag, "")
df['Outflow'] = np.where(df.Betrag < 0, df.Betrag * (-1), "")
path = (root.filenames.replace('Download_Finanzblick', 'Converted_YNAB')[:-4] + '-converted.csv')
print(path)
df.to_csv(path, sep=';', index=False,
          columns=['Date', 'Payee', 'Memo', 'Inflow', 'Outflow'], decimal='.')
next(item)

和错误消息:

  

“ C:\ Program Files(x86)\ Microsoft Visual   Studio \ Shared \ Anaconda3_64 \ python.exe”   “ C:/用户/ dangeph /存储库/ Finanzblick YNAB / Testfile.py”   ('C:/ Users / dangeph / Desktop / Favoriten / Privat / YNAB / Download_Finanzblick / 2019_YY / Amazon   -Kopie.csv','C:/ Users / dangeph / Desktop / Favoriten / Privat / YNAB / Download_Finanzblick / 2019_YY / Amazon   -Kopie-converted.csv','C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/Amazon.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/Amazon-converted.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/DB.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/DiBA.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/DKB.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/DKB-Visa.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/Paypal.csv',   'C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/VB.csv')   C:/用户/ dangeph /桌面/收藏夹/ Privat / YNAB / Download_Finanzblick / 2019_YY / Amazon   -Kopie.csv C:/ Users / dangeph / Desktop / Favoriten / Privat / YNAB / Download_Finanzblick / 2019_YY / Amazon   -Kopie-converted.csv C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/Amazon.csv   C:/用户/ dangeph /桌面/收藏夹/Privat/YNAB/Download_Finanzblick/2019_YY/Amazon-converted.csv   C:/用户/ dangeph /桌面/收藏夹/Privat/YNAB/Download_Finanzblick/2019_YY/DB.csv   C:/用户/ dangeph /桌面/收藏夹/Privat/YNAB/Download_Finanzblick/2019_YY/DiBA.csv   C:/用户/ dangeph /桌面/收藏夹/Privat/YNAB/Download_Finanzblick/2019_YY/DKB.csv   C:/用户/ dangeph /桌面/收藏夹/Privat/YNAB/Download_Finanzblick/2019_YY/DKB-Visa.csv   C:/Users/dangeph/Desktop/Favoriten/Privat/YNAB/Download_Finanzblick/2019_YY/Paypal.csv   C:/用户/ dangeph /桌面/收藏夹/Privat/YNAB/Download_Finanzblick/2019_YY/VB.csv   追溯(最近一次通话):文件   “ C:/ Users / dangeph / Repository / Finanzblick YNAB / Testfile.py”,第21行,   在       编码='utf-8',十进制=',')文件“ C:\ Program Files(x86)\ Microsoft Visual   Studio \ Shared \ Anaconda3_64 \ lib \ site-packages \ pandas \ io \ parsers.py”,   parser_f中的第678行       返回_read(filepath_or_buffer,kwds)文件“ C:\ Program Files(x86)\ Microsoft Visual   Studio \ Shared \ Anaconda3_64 \ lib \ site-packages \ pandas \ io \ parsers.py”,   _read中的第424行       filepath_or_buffer,编码,压缩)“ C:\ Program Files(x86)\ Microsoft Visual   Studio \ Shared \ Anaconda3_64 \ lib \ site-packages \ pandas \ io \ common.py”,   第218行,位于get_filepath_or_buffer中       引发ValueError(msg.format(_type = type(filepath_or_buffer)))ValueError:无效的文件路径或缓冲区对象类型:

     

以退出代码1完成的过程

0 个答案:

没有答案