2017-10-15 6 views
1

私は、.csvファイルを開き、後で別のモジュールの入力として使用するいくつかのパラメータを読み込む、pandasを使用してPythonコードを作成しています。コードが読み取る必要があるパラメータに沿って、内部ネットワークに、後で最終出力に組み込む必要があるデータを含む他の.csvファイルの場所(パス)があります。私の問題はそれらのファイルを開くことです。明示的にパスを定義しない限り(最終コードに必要なすべての.csvファイルをループするための参照変数を使用する代わりに)、ValuError:無効なファイルパスまたはバッファオブジェクトタイプを取得します。Pythonでパスを開くときの問題

パスに一重引用符と二重引用符を追加しようとしましたが、それは役に立ちませんでした。誰かが私が間違っていることを理解するのを助けることができますか?

以下は、問題を明確にするのに役立つ私のコードの一部です。

ご協力いただきありがとうございます。

Root_path = c_input_df.loc["HF Modeling folder full path"] 
Input_path = Root_path + c_input_df.loc["FO_Input_Files folder name & location"] 

次に細胞

Input_path 
Parameters C:/Users/Pegaso/AnacondaProjects/2.-SuperFO/2.Projects/Client_ABC/Internal Data/HF Modeling/FO_Input_Files/1.-Model_13102017/UNI-09_original/ 
dtype: object 

次に細胞

well_name 
Parameters 'UNI-09' 
Name: Well name, dtype: object 
#those two strings (Input path and well_name) are used to tell the path and part of the name of the .csv file to open 

次に細胞

#This is the prefered method to read the dataframe: 
FT_file = pd.read_csv(Input_path + "FT-" + well_name + ".csv") 
#But it gives the following error: 
ValueError: Invalid file path or buffer object type: <class 'pandas.core.series.Series'> 

次に細胞

#Since the method above gives an error, I used the explicit path: 
FT_file = Input_path + "FT-" + well_name + ".csv" 
FT_file 
Parameters C:/Users/Pegaso/AnacondaProjects/2.-SuperFO/2.Projects/Client_ABC/Internal Data/HF Modeling/FO_Input_Files/1.-Model_13102017/UNI-09_original/FT-UNI-09.csv 
dtype: object 

#When I try the path directly in the pd.read_csv function, it reads the file 
FT_file = pd.read_csv("C:/Users/Pegaso/AnacondaProjects/2.-SuperFO/2.Projects/Client_ABC/Internal Data/HF Modeling/FO_Input_Files/1.-Model_13102017/UNI-09_original/FT-UNI-09.csv") 
FT_file 
Par_1 Par_2 Par_3 
0 Units_1 Units_2 Units_3 
1 6630 2448.270301 3659.999055 
2 6647.99982 2448.270301 3659.999055 

私は自分自身を理解させていただきたいと思いますが、そうでない場合はお知らせください。私は問題をより詳しく説明しようとします。

RGDS、

ペガソなぜ

答えて

0

わからまだないが、問題は、このコード行にあった:

Root_path = c_input_df.loc["HF Modeling folder full path"] 

私が使用している場合は、メソッドastype(strが)

を.Parameters
root_path = c_input_df.loc["HF Modeling folder abs path"].astype(str).Parameters 

私が探していた結果が得られました。ただの文字列です。それを見てください:

root_path = c_input_df.loc["HF Modeling folder abs path"] #.astype(str).Parameters 
    print root_path 

Parameters L:/Data/Jose/2.-SuperFO_testing/1612-02_University_9-319H_FleurDeLis/Internal Data/HF Modeling/ 
Name: HF Modeling folder abs path, dtype: object 

...と私は最後

root_path = c_input_df.loc["HF Modeling folder abs path"] .astype(str).Parameters 
    print root_path 

L:/Data/Jose/2.-SuperFO_testing/1612-02_University_9-319H_FleurDeLis/Internal Data/HF Modeling/ 

でパラメータを追加するとき、私は私の問題は解決しましたが、私は、この動作は、データをインポートする際に理由をよりよく理解したいと思いますデータフレームから。

RGDS、

ペガソ

関連する問題