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 8529147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:57:55+00:00 2026-06-11T08:57:55+00:00

I have a Pandas dataframe ‘dt = myfunc()’ , and copy the screen output

  • 0

I have a Pandas dataframe ‘dt = myfunc()’ , and copy the screen output from IDLE as below:

>>> from __future__ import division
>>> dt = __get_stk_data__(['*'], frq='CQQ', from_db=False) # my function
>>> dt = dt[dt['ebt']==0][['tax','ebt']]
>>> type(dt)
<class 'pandas.core.frame.DataFrame'>
>>> dt
                tax ebt
STK_ID RPT_Date        
000719 20100331   0   0
       20100630   0   0
       20100930   0   0
       20110331   0   0
002164 20080331   0   0
300155 20120331   0   0
600094 20090331   0   0
       20090630   0   0
       20090930   0   0
600180 20090331   0   0
600757 20110331   0   0
>>> dt['tax_rate'] = dt.tax/dt.ebt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Python\Lib\site-packages\pandas\core\series.py", line 72, in wrapper
    return Series(na_op(self.values, other.values),
  File "D:\Python\Lib\site-packages\pandas\core\series.py", line 53, in na_op
    result = op(x, y)
ZeroDivisionError: float division
>>> 

It costs me a lot time to figure out why Pandas raises the ‘ZeroDivisionError: float division’ , while Pandas works very well for below sample code:

tuples = [('000719','20100331'),('000719','20100930'),('002164','20080331')]
index = MultiIndex.from_tuples(tuples, names=['STK_ID', 'RPT_Date'])
dt =DataFrame({'tax':[0,0,0],'ebt':[0,0,0]},index=index)
dt['tax_rate'] = dt.tax/dt.ebt

>>> dt
                 ebt  tax  tax_rate
STK_ID RPT_Date                    
000719 20100331    0    0       NaN
       20100930    0    0       NaN
002164 20080331    0    0       NaN
>>> 

I expect Pandas offer ‘NaN’ for both cases, why ‘ZeroDivisionError’ happens in first case ? How to fix it ?


below codes & screen output is attached to provide further information to debug

def __by_Q__(df):
    ''' this function transforms the input financial report data (which
        is accumulative) to qurterly data
    '''
    df_q1=df[df.index.map(lambda x: x[1].endswith("0331"))]

    print 'before diff:\n'
    print df.dtypes
    df_delta = df.diff()
    print '\nafter diff: \n'
    print df_delta.dtypes


    q1_mask = df_delta.index.map(lambda x: x[1].endswith("0331"));
    df_q234 = df_delta[~q1_mask]

    rst = concat([df_q1,df_q234])

    rst=rst.sort_index()
    return rst

screen output:

before diff:

sales                      float64
discount                    object
net_sales                  float64
cogs                       float64
ebt                        float64
tax                        float64

after diff: 

sales                      object
discount                   object
net_sales                  object
cogs                       object
ebt                        object
tax                        object
  • 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-11T08:57:56+00:00Added an answer on June 11, 2026 at 8:57 am

    @bigbug, how are you getting the data out of the SQLite backend? If you look in pandas.io.sql, the read_frame method has a coerce_float parameter that should convert numerical data to float if possible.

    Your second example works because the DataFrame constructor tries to be clever about types. If you set the dtype to object then it fails:

    In [16]: dt = DataFrame({'tax':[0,0,0], 'ebt':[0,0,0]},index=index,dtype=object)
    
    In [17]: dt.tax/dt.ebt
    ---------------------------------------------------------------------------
    ZeroDivisionError                         Traceback (most recent call last)
    

    Check your data importing code again and let me know what you find?

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

Sidebar

Related Questions

I have the data below saved as a pandas dataframe . With this data,
I have a dataframe generated from Python's Pandas package. How can I generate heatmap
I have a pandas DataFrame with a date column. It is not an index.
I have a pandas dataframe consisting of 23 series with a default sequential index
Assume I have a pandas DataFrame with two columns, A and B. I'd like
I have a Python pandas DataFrame rpt : rpt <class 'pandas.core.frame.DataFrame'> MultiIndex: 47518 entries,
I'd like to create a pandas DataFrame from the following csv file: ........... EUR
I have a Pandas dataframe, and i want to plot it as matplotlib table.
I have a pandas dataframe object that looks like this: one two three four
I have a Pandas DataFrame with four columns, A, B, C, D . It

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.