Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:07:11+00:00 2026-06-18T11:07:11+00:00

I have a df: df: a b c date 2012-01-01 0.50 1.2 0.70 2012-01-01

  • 0

I have a df:

df:
               a      b       c
date
2012-01-01   0.50    1.2    0.70 
2012-01-01   0.45    1.2    0.65
2012-01-01   0.65    1.2    0.63
2012-01-01   0.75    1.2    0.29
2012-01-01   -0.25   1.2    -0.68

I want to calculate: a/b – c

I run:

new = df['a']/df['b'] - df['c']

This returns
new:

date
2012-01-01   -0.2833 
2012-01-01   -0.2750
2012-01-01   -0.0883
2012-01-01   0.3350
2012-01-01   0.4717

First error:
If I go:

new.ix[0][0]
TypeError: 'NumericType' object is unsubscriptable

So I assume it’s a series.

So I change it to:

new = pd.DataFrame(new)
type(new.ix[0][0])

<type 'NumericType'>

This is the weird part:

new.ix[0][0]
-0.2833
new.ix[0][0]/2
-0.141650
new.ix[0][0]/2.0
0

What is going on with the number type? How can I change it to float? What is the best practice here?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:07:13+00:00Added an answer on June 18, 2026 at 11:07 am

    The reason for the differences in behaviour is when new is a Series vs. a DataFrame.

    The first new you create is a Series:

    In [11]: s = new = df['a'] / df['b'] - df['c']
    
    In [12]: type(s)
    Out[12]: pandas.core.series.Series
    

    This has a value in position 0 of -0.2833:

    In [13]: s.ix[0]
    Out[13]: -0.28333333333333327
    

    (You can’t __getitem__ on a float e.g. 2.0[0] gives you a similar error.)

    However, when you then force it to a DataFrame:

    In [14]: df_new = new = pd.DataFrame(s)
    
    In [15]: df_new
    Out[15]: 
              0
    0 -0.283333
    1 -0.275000
    2 -0.088333
    3  0.335000
    4  0.471667
    
    In [16]: type(df_new)
    Out[16]: pandas.core.frame.DataFrame
    

    this time the 0th index is a Series (row):

    In [17]: df_new.ix[0]
    Out[17]: 
    0   -0.283333
    Name: 0
    
    In [18]: df_new.ix[0][0]
    Out[18]: -0.28333333333333327
    

    Update:

    To ensure that all your DataFrames values are floats (numpy.float64) you can applymap (which works here since every column is being converted to a float):

    df = df.applymap(float)
    

    I don’t know how you got NumericType object, I assume the divide by 2 vs 2.0 derives from this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have date 2012-04-02 10:01:00 am I want to show this date in with
I have a date with weeks using this format: 2012-15 - 2012-20 I want
i have input xml as <content> <date> <day>14</day> <month>06</month> <year>2012</year> </date> </content> want it
I have a date in NSString format with this content: 29/02/2012 12:00:00 AM I'm
I have a date as follows. $discount_start_date='03/27/2012 18:47'; $start_date=new DateTime($discount_start_date); $start_date->format('Y/m/d H:i:s'); How can
i have date showing like the following 01-Nov-2012 12:00:00 AM and i want to
I have date 2012/09/26 . I want to convert it to string using PHP.How
i have one date value coming from database and i want to calculate difference
I want to calculate number of days from a date. For example, we have
I have this problem with Safari not recognizing the date format 2012-01-03 (being 2012

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.