RuntimeWarning pandas

Viewed 617

I keep on getting a RuntimeWarning: unorderable types: str() < int(), sort order is undefined for incomparable objects result = result.union(other) from the following code. Not entirely sure where or what I am doing wrong. I'm trying to get a dataset looking like this.

df = pd.read_excel('/Users/user/Desktop/------/data.xlsx')
df.rename(columns={'Product Installed Fiscal Quarter': 'Quarter', 'Serviceable Product #': 'Product Code', 'Sold To Customer Name': 'Account', 'Orderable Product Description': 'Product'}, inplace=True)
df.drop(['# of Licenses'], axis=1, inplace=True)

def all_products():
    products = []
    for index, row in df.iterrows():
        if row['Serviceable Product Description'] not in products:
            products.append(row['Serviceable Product Description'])
    products.insert(0, 'Account')
    products.insert(1, 'Time')
    return products

header = all_products()
xd = pd.DataFrame(columns= header)

def reformatted_data():    
    for index, row in df.iterrows():
        add = [0] * len(header)
        add.insert(0, row['Account'])
        add.insert(1, row['Quarter'])
        index = header.index(row['Serviceable Product Description'])
        add[index] = row['Quantity']
        xd.append(add)
    return xd
reformatted_data()
1 Answers

When reading from Excel, it is important to mind your data types. Pandas makes a good guess most of the time but it is advisable to explicitly cast columns you will be working with extensively. For example, a column in excel can have strings and numbers without concern however Pandas requires a column to be a uniform type. As a result, Pandas will cast that column to string silently. Beware.

Related