[英]TypeError: A common type cannot be infered from types float, string in python
我可以在DataFrame中從這里獲取數據。 當我使用graphlab將DataFrame轉換為SFrame時,顯示以下錯誤:
TypeError:不能從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
數據顯示在此行的DataFrame中。當我將DataFrame轉換為Sframe時,它會出錯。
DataFrame使用.Sframe()方法轉換為SFrame
t_data = graphlab.SFrame(df9)
T_DATA
根據我的數據格式良好或可能不是。 我也試過兩個解決方案,但它對我不起作用。
1)我檢查了每一列但沒有列有不同的數據類型。
2)我使用了特定數據類型的每一列
df.column_name.astype(str)
和df ['column_name'] = 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?
嘗試這種語法進行轉換:
df['column_name'] = df['column_name'].astype(float)
df['column_name'] = df['column_name'].astype(str)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.