【发布时间】:2019-12-13 11:41:06
【问题描述】:
当我打印出该值时,它很好。但最后它给出了一个错误,因为 b' 把名字弄乱了。我正在读取文件 f0.txt、f1.txt;计划修改它们并用相同的名称保存它们。
尝试了a similar question here 提供的 utf-8 解码解决方案,但不起作用。
path ='/kaggle/input/'
print (path)
i = 1
part = 'f' + str(i)
print (part) #the byte literal symbol b' doesn't appear here
for i in range(0,3):
part = 'f' + str(i)
file_path = path + part + '.csv'
print (file_path) # the byte literal symbol b' doesn't appear here too
pd = pd.read_csv(file_path, delim_whitespace = True) # error in this line
np.savetxt(part.txt, pd,fmt='%.18e', delimiter=',', newline='n', header='Time,ID,lat,long,speed',)
b'/kaggle/input/f0.csv' does not exist
命令
pd.read_csv('/kaggle/input/f2.txt', delim_whitespace = True)
正在工作。
第一种情况的错误是:
FileNotFoundError Traceback (most recent call last)
<ipython-input-33-37d9e9ecc542> in <module>
8 file_path = path + part + '.csv'
9 print (file_path)
---> 10 pd = pd.read_csv(file_path, delim_whitespace = True)
11 np.savetxt(part.txt, pd,fmt='%.18e', delimiter=',', newline='n', header='Time,ID,lat,long,speed',)
12
/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py in parser_f(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, escapechar, comment, encoding, dialect, tupleize_cols, error_bad_lines, warn_bad_lines, skipfooter, doublequote, delim_whitespace, low_memory, memory_map, float_precision)
676 skip_blank_lines=skip_blank_lines)
677
--> 678 return _read(filepath_or_buffer, kwds)
679
680 parser_f.__name__ = name
/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py in _read(filepath_or_buffer, kwds)
438
439 # Create the parser.
--> 440 parser = TextFileReader(filepath_or_buffer, **kwds)
441
442 if chunksize or iterator:
/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, f, engine, **kwds)
785 self.options['has_index_names'] = kwds['has_index_names']
786
--> 787 self._make_engine(self.engine)
788
789 def close(self):
/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py in _make_engine(self, engine)
1012 def _make_engine(self, engine='c'):
1013 if engine == 'c':
-> 1014 self._engine = CParserWrapper(self.f, **self.options)
1015 else:
1016 if engine == 'python':
/opt/conda/lib/python3.6/site-packages/pandas/io/parsers.py in __init__(self, src, **kwds)
1706 kwds['usecols'] = self.usecols
1707
-> 1708 self._reader = parsers.TextReader(src, **kwds)
1709
1710 passed_names = self.names is None
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader.__cinit__()
pandas/_libs/parsers.pyx in pandas._libs.parsers.TextReader._setup_parser_source()
FileNotFoundError: File b'/kaggle/input/f0.csv' does not exist
【问题讨论】:
-
你知道文件系统有自己的编码吗?
-
@wjandrea 不,我刚开始研究 python。文件系统是指操作系统还是编译器?
-
A filesystem 基本上是一个保存文件的数据结构。但无论如何,看看格里斯玛的回答,这并不相关。
标签: python python-3.x pandas