简体   繁体   English

TypeError:不能从python类型float,string中引用常见类型

[英]TypeError: A common type cannot be infered from types float, string in python

I'm able to get the data from here in DataFrame. 我可以在DataFrame中从这里获取数据。 When I'm converting the DataFrame into SFrame using graphlab then this error is showing: 当我使用graphlab将DataFrame转换为SFrame时,显示以下错误:

TypeError: A common type cannot be infered from types float, string. TypeError:不能从float,string类型中引用常见类型。

My Code is 我的代码是

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

Data is showing in DataFrame at this line..When I convert the DataFrame into Sframe, It gives error. 数据显示在此行的DataFrame中。当我将DataFrame转换为Sframe时,它会出错。

DataFrame converts into SFrame using .Sframe() method DataFrame使用.Sframe()方法转换为SFrame

t_data = graphlab.SFrame(df9) t_data = graphlab.SFrame(df9)

t_data T_DATA

and according to me Data is in well format or may be not. 根据我的数据格式良好或可能不是。 And also I tried two solution but it didn't work for me. 我也试过两个解决方案,但它对我不起作用。

1) I checked every column but no column has different data type. 1)我检查了每一列但没有列有不同的数据类型。

2) I converted every column in a specific data type using 2)我使用了特定数据类型的每一列

df.column_name.astype(str) and df['column_name']= df[coulmn_name].astype(str) df.column_name.astype(str)和df ['column_name'] = df [coulmn_name] .astype(str)

but it didn't work any more. 但它不再起作用了。

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.**

How can I convert this DataFrame into SFrame? 如何将此DataFrame转换为SFrame?

try this syntax for conversion: 尝试这种语法进行转换:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM