Explore Courses Blog Tutorials Interview Questions
0 votes
in Azure by (45.3k points)

I am facing an error when we have a column which has datatype as a string and the value like col1 col2 1 .89

So, when I am using:

def azureml_main(dataframe1 = None, dataframe2 = None):

    # Execution logic goes here

    print('Input pandas.DataFrame #1:')

    import pandas as pd

    import numpy as np

    from sklearn.kernel_approximation import RBFSampler

    x =dataframe1.iloc[:,2:1080]

    print x

    df1 = dataframe1[['colname']]

    change = np.array(df1)

    b = change.ravel()

    print b

    rbf_feature = RBFSampler(gamma=1, n_components=100,random_state=1)

    print rbf_feature

    print "test"

    X_features = rbf_feature.fit_transform(x)

After this, I am getting an error as can't convert non-int into type float

1 Answer

0 votes
by (16.8k points)

If you're running version 0.17.0 or later then convert_objects has been replaced with the methods: to_numericto_datetime, and to_timestamp so instead of:

df['col'] = df['col'].astype(float)

You can do:

df['col'] = pd.to_numeric(df['col'])

Note that by default any non convertible values will raise an error, if you want these to be forced to NaN then do:

df['col'] = pd.to_numeric(df['col'], errors='coerce')

Browse Categories