2017-06-23 51 views
-1

我可以在DataFrame中獲取數據from here。當我使用graphlab將數據幀到SFrame那麼這個錯誤顯示:TypeError:常見類型不能從類型float,python中的字符串中傳遞

TypeError: A common type cannot be infered from types float, string.

我的代碼是

import graphlab 

import pandas as pd 

import numpy as np 

import matplotlib.pyplot as pt 

from numpy import array 

from graphlab import SFrame 


user_columns =['No','User id','User Name','Skill','Given Test Name','Given Test ID','Recommend Test','Recommend Test ID','Time Start','Time End','Score','Max Score'] 

data=pd.read_table('http://tech4partner.com.cp-in-5.webhostbox.net/recommend_test.php', sep='^',header=None,names = user_columns) 

df2 = data.ix[2:] 

df3=df2.reset_index() 

df4=df3.drop('index', axis=1) 

df5=df4.drop(df4.index[len(df4)-1]) 

df5=df5.reset_index(1,[len(df5)-1]) 

df7 = df5.reset_index() 

df8=df7.drop('index', axis=1) 

df9=df8.head(len(df8)) 

df9.index = np.arange(1, len(df9) + 1) 

df9=df9.head(50) 

df9 

的數據顯示,在此line..When在數據幀轉換我的數據框成Sframe,它會給出錯誤。

DataFrame converts into SFrame using .Sframe() method

t_data = graphlab.SFrame(df9)

t_data

並根據我數據格式良好或可能不是。而且我嘗試了兩種解決方案,但它對我沒有用。

1)我檢查了每列,但沒有列具有不同的數據類型。

2)我使用

df.column_name.astype(str)和df [ '列名'] = DF一個特定的數據類型轉換的每一列[coulmn_name] .astype(STR)

但它沒有工作任何更多。

TypeError         Traceback (most recent call last) 
<ipython-input-11-c852cd1e7f45> in <module>() 
----> 1 t_data = graphlab.SFrame(df9) 
     2 t_data 
     3 
C:\Anaconda2\lib\site-packages\graphlab\data_structures\sframe.pyc in __init__(self, data, format, _proxy) 
    951      pass 
    952     else: 
--> 953      raise ValueError('Unknown input type: ' + format) 
    954 
    955   sframe_size = -1 
C:\Anaconda2\lib\site-packages\graphlab\cython\context.pyc in __exit__(self, exc_type, exc_value, traceback) 
    47    if not self.show_cython_trace: 
    48     # To hide cython trace, we re-raise from here 
---> 49     raise exc_type(exc_value) 
    50    else: 
    51     # To show the full trace, we do nothing and let exception propagate 
**TypeError: A common type cannot be infered from types float, string.** 

如何將此DataFrame轉換爲SFrame?

+0

請閱讀(// meta.stackoverflow .com/q/326569) - 總結是這不是解決志願者問題的理想方法,而且可能對獲得答案起反作用。請不要將這添加到您的問題。 – halfer

+0

感謝您的評論,如果您覺得我寫錯了「緊急」和「儘快」,這是不可接受的,然後對不起。我不介意你可以降低我的問題。 –

+0

讓我告訴你一件事,我在Anaconda使用Jupyter。我已經在Jupyter中創建了一個腳本,DataFrame可以很容易地轉換爲SFrame而不會有任何麻煩.Thanx Halfer –

回答

0

試試這個語法轉換:[?在什麼情況下我想補充「緊急」或其他類似的短語我的問題,爲了獲得更快的答案]

df['column_name'] = df['column_name'].astype(float) 
df['column_name'] = df['column_name'].astype(str) 
+0

我也使用過這種語法..它不適合我..現在我編輯了我的問題並共享完整的代碼看到.... –

相關問題