0
我指的是this我在几天前发布的问题,我还没有得到任何答复,我怀疑情况没有被正确描述,我做了一个更简单的设置这将更容易理解,并希望。从有经验的程序员那里获得更多关注!从.csv文件导入字符串形成路径的问题
我忘了提,我就Jupyter
import pandas as pd
from pandas import Series, DataFrame
g_input_df = pd.read_csv('SetsLoc.csv')
URL=g_input_df.iloc[0,0]
c_input_df = pd.read_csv(URL)
c_input_df = c_input_df.set_index("Parameter")
root_path = c_input_df.loc["root_1"]
input_rel_path = c_input_df.loc["root_2"]
input_file_name = c_input_df.loc["file_name"]
本节从.csv读取路径列表,只是一个同时运行的Python 2,他们中的每一个引导到其他.csv文件,其中包含使用python进行模拟的输入。
从上面的代码的结果可以在这里进行测试:
c_input_df
Value Parameter
root_1 C:/SimpleTest/
root_2 Input/
file_name Prop_1.csv
URL
'C:/SimpleTest/Sets/Set_1.csv'
root_path+input_rel_path+input_file_name
Value C:/SimpleTest/Input/Prop_1.csv
dtype: object
Property_1 = pd.read_csv('C:/SimpleTest/Input/Prop_1.csv')
Property_1
height weight
0 100 50
1 110 44
2 98 42
...在另一方面,如果我尝试使用varibales描述文件的路径和名称,我得到一个错误:
Property_1 = pd.read_csv(root_path+input_rel_path+input_file_name)
Property_1
我得到以下错误:
ValueErrorTraceback (most recent call last)
<ipython-input-3-1d5306b6bdb5> in <module>()
----> 1 Property_1 = pd.read_csv(root_path+input_rel_path+input_file_name)
2 Property_1
C:\ProgramData\Anaconda2\lib\site-packages\pandas\io\parsers.pyc 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, skip_footer, doublequote, delim_whitespace, as_recarray, compact_ints, use_unsigned, low_memory, buffer_lines, memory_map, float_precision)
653 skip_blank_lines=skip_blank_lines)
654
--> 655 return _read(filepath_or_buffer, kwds)
656
657 parser_f.__name__ = name
C:\ProgramData\Anaconda2\lib\site-packages\pandas\io\parsers.pyc in _read(filepath_or_buffer, kwds)
390 compression = _infer_compression(filepath_or_buffer, compression)
391 filepath_or_buffer, _, compression = get_filepath_or_buffer(
--> 392 filepath_or_buffer, encoding, compression)
393 kwds['compression'] = compression
394
C:\ProgramData\Anaconda2\lib\site-packages\pandas\io\common.pyc in get_filepath_or_buffer(filepath_or_buffer, encoding, compression)
208 if not is_file_like(filepath_or_buffer):
209 msg = "Invalid file path or buffer object type: {_type}"
--> 210 raise ValueError(msg.format(_type=type(filepath_or_buffer)))
211
212 return filepath_or_buffer, None, compression
ValueError: Invalid file path or buffer object type: <class 'pandas.core.series.Series'>}
我beleive,问题存在于PA的方式从数据框中读取构成路径和filenemae的rameter,是否有任何方法可以指定这些参数是路径,或者类似的东西可以避免这个问题?
任何帮助,高度赞赏!
再版(root_path + input_rel_path + input_file_name)产生: “值C:/ SimpleTest/Input/Prop_1.csv \ ndtype:object'非常感谢! – Pegaso
'值C:/SimpleTest/Input/Prop_1.csv \ ndtype:object'给任何人一个线索的问题可能是什么? – Pegaso
SetsLoc.csv只包含的路径和文件名的列表:{Path_and_name C:/SimpleTest/Sets/Set_1.csv C:/SimpleTest/Sets/Set_2.csv C:/ SimpleTest的/套/ Set_3.csv} – Pegaso