2013-04-15 48 views
0

我有一個由csv構建的df,應該是一個double。如果我檢查一個?它似乎是一個字符串。試圖將其轉換爲int(a),我收到一個類型錯誤, 我不知道爲什麼。基數爲10的文字無效

ValueError: invalid literal for int() with base 10: '46.074' 

    a=df["MA10"].ix[100] 
    a=int(a) 


Imported: 
df=pd.read_csv('__.csv',header=None,parse_dates=True, index_col={0},names="__".split()) 

回答

0

使用浮動

In [14]: int('46.074') 
--------------------------------------------------------------------------- 
ValueError        Traceback (most recent call last) 
<ipython-input-14-f8e7b101e6bd> in <module>() 
----> 1 int('46.074') 

ValueError: invalid literal for int() with base 10: '46.074' 

In [15]: float('46.074') 
Out[15]: 46.074 
+0

感謝。想一想,我正在使用iterrows()將它變成一個字符串?它們在數據框中被視爲雙打。 I.E.我使用 作爲idx,df.iterrows()中的行 –

+0

顯示了您的框架在讀入後顯示的內容,並顯示df.get_dtype_counts()。你最終的目標是什麼?你在幹什麼? – Jeff

+0

我看到浮動4,對象10.我的最終目標是在這裏:http://stackoverflow.com/questions/16019275/rolling-record-of-first-time-changes-diffs-between-two-columns-in-a -df –

0

試試這個

int(float('46.074')//1) 
相關問題