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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:44:54+00:00 2026-06-17T15:44:54+00:00

I’m dealing with a balance sheet which I’ve parsed into pandas using: table =

  • 0

I’m dealing with a balance sheet which I’ve parsed into pandas using:

    table = xls_file.parse('Consolidated_Balance_Sheet')
    table.ix[:, 1]

    0         None
    1         None
    2      $ 3,029
    3         1989
    5         None
    6     $ 34,479

I’m trying to identify the rows with unicode and strip the $ sign and comma, converting to float.

    for row in table.ix[:, 1]:
        if isinstance(row, unicode):
            print type(row), row
            num = float(row.lstrip('$').replace(',',''))
            print num
            row = num
            print type(row), row

This produces the following output:

    <type 'unicode'> $ 3,029
    3029.0
    <type 'float'> 3029.0
    <type 'unicode'> $ 34,479
    34479.0
    <type 'float'> 34479.0

However, the value is unchanged when I check the table

    table.ix[2, 1]
    u'$ 3,029'

How can I correctly change the value to a float?

EDIT: Thanks for the two responses, I can reproduce those with no problem. However when I use the apply function to my case I get an ‘unhashable type’ error.

In [167]: thead = table.head()
In [168]: thead

Out[168]:
         Consolidated Balance Sheet (USD $)  Sep. 30, 2012  Dec. 31, 2011
    0    In Millions, unless otherwise specified     None    None
    1    Current assets                              None    None
    2    Cash and cash equivalents                   $ 3,029 $ 2,219
    3    Marketable securities - current             1989    1461
    4    Accounts receivable - net                   4409    3867

In [170]: def no_comma_or_dollar(num):
              if isinstance(num, unicode):
                  return float(num.lstrip('$').replace(',',''))
              else:
                  return num

          thead[:, 1] = thead[:, 1].apply(no_comma_or_dollar)

Produces the following:

 TypeError: unhashable type

I can’t get my head around why as I’m not changing the keys, just the values. Is there another way to change the values in the dataframe?

EDIT2:

In [171]: thead.to_dict()
Out[171]: {u'Consolidated Balance Sheet (USD $)': {0: u'In Millions, unless otherwise specified',
  1: u'Current assets',
  2: u'Cash and cash equivalents',
  3: u'Marketable securities - current',
  4: u'Accounts receivable - net'},
 u'Dec. 31, 2011': {0: None, 1: None, 2: u'$ 2,219', 3: 1461.0, 4: 3867.0},
 u'Sep. 30, 2012': {0: None, 1: None, 2: u'$ 3,029', 3: 1989.0, 4: 4409.0}}
  • 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-17T15:44:56+00:00Added an answer on June 17, 2026 at 3:44 pm

    You are just printing these and not apply-ing them to the DataFrame, here’s one way to do it:

    Create a function to do the striping (if unicode) or leave it if already a number:

    def no_comma_or_dollar(num):
        if isinstance(num, unicode):
            return float(num.lstrip('$').replace(',',''))
        else:
            return num
    
    table[col_name] = table[col_name].apply(no_comma_or_dollar)
    

    For example:

    df = pd.DataFrame([[u'$1,000'], [200.]])
    
    In [3]: df[0].apply(no_comma_or_dollar)
    Out[3]: 
    0    1000
    1     200
    Name: 0
    

    Update:

    With the thread which you give, I would be tempted to give a slightly lazier version of no_comma_or_dollar and applymap:

    def no_comma_or_dollar2(num):
        try:
            return float(num.lstrip('$').replace(',',''))
        except: # if you can't strip/replace/convert just leave it
            return num
    
    In [5]: thread.applymap(no_comma_or_dollar2)
    Out[5]: 
            Consolidated Balance Sheet (USD $)  Dec. 31, 2011  Sep. 30, 2012
    0  In Millions, unless otherwise specified            NaN            NaN
    1                           Current assets            NaN            NaN
    2                Cash and cash equivalents           2219           3029
    3          Marketable securities - current           1461           1989
    4                Accounts receivable - net           3867           4409
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am using JSon response to parse title,date content and thumbnail images and place
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I am using jsonparser to parse data and images obtained from json response. When
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.