达斯克抛出filenotfounderror读取csv /在熊猫中工作正常

时间:2019-05-26 17:32:33

标签: python pandas dataframe dask dask-distributed

我试图将一些Pandas代码移植到Dask,并且在读取csv时遇到问题-看来Dask在读取操作中将本地工作目录添加到了文件路径中。当我使用Pandas阅读时,效果很好。

我正在使用Windows10。工作目录位于我的C驱动器上;数据在我的D盘中。

熊猫代码:

import pandas as pd

file_path = 'D:/test_data/'
item = filename.csv
temp_df = pd.read_csv(file_path + item, usecols=['time', 'ticker_price'])

打印输出(temp_df.head()):

                         time  ticker_price
0  2019-05-15 09:34:09.233373       0.02843
1  2019-05-15 09:34:11.334135       0.02843
2  2019-05-15 09:34:12.147282       0.02843
3  2019-05-15 09:34:13.705145       0.02843
4  2019-05-15 09:34:14.521257       0.02843
type = <class 'pandas.core.frame.DataFrame'>

快捷代码:

import dask.dataframe as dd

file_path = 'D:/test_data/'
item = filename.csv
temp_dd = dd.read_csv(file_path + item, usecols=['time', 'ticker_price'])

打印输出(temp_dd.head()):

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Dan\\PycharmProjects\\project1_folder/D:/test_data/filename.csv'

看起来Dask会将file_path附加到D驱动器上的数据中,并附加到本地工作目录(PycharmProjects文件夹)的路径中,而Pandas则没有。有什么解决方案吗?

我尝试过的一些方法不起作用:

(1)

temp_file_path_str = pathlib.Path(file_path + item)
temp_dd = dd.read_csv(temp_file_path_str, usecols=['time', 'ticker_price'])

这将返回相同的错误:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Dan\\PycharmProjects\\project1_folder/D:\\test_data\\filename.csv'

(2)

temp_file_path_str = 'file://' + file_path + item
temp_dd = dd.read_csv(temp_file_path_str, usecols=['time', 'ticker_price'])

这将返回一个错误,提示Dask从路径中删除了驱动器ID:

FileNotFoundError: [WinError 3] The system cannot find the path specified: '\\test_data\\filename.csv'

(3)

temp_file_path_str = 'file://' + file_path + item
temp_file_path_str = pathlib.Path(temp_file_path_str)
temp_dd = dd.read_csv(temp_file_path_str, usecols=['time', 'ticker_price'])

这似乎在路径中的驱动器ID之前添加了一个额外的\:

OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\\D:\\test_data\\filename.csv'

更新19/6/1 -我为此创建了一个问题:https://github.com/dask/dask/issues/4861

0 个答案:

没有答案
相关问题