繁体   English   中英

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

[英]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.

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