2016-11-16 11 views
0

"例外TypeError ()は正確に1引数(5が与えられた)を取る" 私はフォーマットされているCSVを持っている: PythonのパンダCSV:

"Year","Month","Day","Hour","Minute","Direct","Diffuse","D_Global","D_IR","U_Global","U_IR","Zenith" 
2001,3,1,0,1,0.28,84.53,83.53,224.93,76.67,228.31,80.031 
2001,3,1,0,2,0.15,84.24,83.25,224.76,76.54,228.62,80.059 
2001,3,1,0,3,0.16,84.63,83.43,225.62,76.76,229.06,80.087 
2001,3,1,0,4,0.20,85.20,83.99,226.56,77.15,228.96,80.115 

そして、私のスクリプトは次のとおりです。

df1 = pd.read_csv(input_file, 
     sep = ",", 
     parse_dates = {'Date': [0,1,2,3,4]}, 
     date_parser = lambda x: pd.to_datetime(x, format="%Y %m %d %H %M"), 
     index_col = ['Date']) 

エラー私が取得することです:

Traceback (most recent call last): 
    File "convertCSVtoNC.py", line 70, in <module> 
    openFile(sys.argv[1:]) 
    File "convertCSVtoNC.py", line 30, in openFile 
    df2 = createDataFrame(input_file, counter) 
    File "convertCSVtoNC.py", line 43, in createDataFrame 
    index_col = ['Date']) 
... 
TypeError: <lambda>() takes exactly 1 argument (5 given) 

スクリプトは302の以前の入力、例をフォーマットするための細かい実行されます。

"Year","Month","Day","Hour","Minute","Direct","Diffuse","D_Global","D_IR","U_Global","U_IR","Zenith" 
1976,1,1,0,3,-999.00,-999.00,-999.00,-999.00,-999.00,-999.00,95.751 
1976,1,1,0,6,-999.00,-999.00,-999.00,-999.00,-999.00,-999.00,95.839 
1976,1,1,0,9,-999.00,-999.00,-999.00,-999.00,-999.00,-999.00,95.930 
1976,1,1,0,12,-999.00,-999.00,-999.00,-999.00,-999.00,-999.00,96.023 

なぜでしょうか?

答えて

1

それは私のために正常に動作します:

df1 = pd.read_csv(file_name, parse_dates={'Date':[0,1,2,3,4]}, 
        date_parser=lambda x: pd.to_datetime(x, format='%Y %m %d %H %M'), 
        index_col=['Date'])) 


In [215]: df1 
Out[215]: 
        Direct Diffuse D_Global D_IR U_Global U_IR Zenith 
Date 
2001-03-01 00:01:00 0.28 84.53  83.53 224.93  76.67 228.31 80.031 
2001-03-01 00:02:00 0.15 84.24  83.25 224.76  76.54 228.62 80.059 
2001-03-01 00:03:00 0.16 84.63  83.43 225.62  76.76 229.06 80.087 
2001-03-01 00:04:00 0.20 85.20  83.99 226.56  77.15 228.96 80.115 

PS私は

0

パンダ0.19.1を使用していますが、私の入力csvファイルの最後にいくつかの新しい行の文字があったが判明します。私はラムダ関数が入力としてすべての行を取っていたので、これは意味をなさないと思います。多分将来のラムダ関連の質問を探すための何か。