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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:41:14+00:00 2026-06-17T13:41:14+00:00

I have pandas DataFrame. I would like to get single value from a column

  • 0

I have pandas DataFrame. I would like to get single value from a column based on a condition involving two another column. I am looking for the value from the column3 for which is the biggest distance in the column1 and 2.

I build the simple example which works:

d = pd.DataFrame({'c1':[.1,3,11.3],'c2':[3,6,.6],'c3':[8,.8,10.9]})
print'data d=\n%s\n' % d                                               
x = float(d.c3[abs(d.c1-d.c2)==max(abs(d.c1-d.c2))].values)
print 'the value of x= \n%s\n' % x

The output from this example is as I expect:

     c1   c2    c3
0   0.1  3.0   8.0
1   3.0  6.0   0.8
2  11.3  0.6  10.9

the value of x= 
10.9

I try to apply exactly the same logic to my original problem with large dataframe inside a class. The code is:

yInit = float(self.DenFrame.Depth[abs(self.DenFrame.Hper-self.DenFrame.Vper)==max(abs(self.DenFrame.Hper-self.DenFrame.Vper))].values)

but this code produce an error:

...
  File "C:\Python27\lib\site-packages\pandas-0.9.0-py2.7-win32.egg\pandas\core\series.py", line 73, in wrapper
return Series(na_op(self.values, other.values),
  File "C:\Python27\lib\site-packages\pandas-0.9.0-py2.7-win32.egg\pandas\core\series.py", line 59, in na_op
result[mask] = op(x[mask], y[mask])
TypeError: unsupported operand type(s) for -: 'str' and 'str'

I found in here that there could be a problem with type of the columns but Depth is type numpy.float64 Hper is type float Vper is type float so I understand how it can apply to my problem.

I don’t know from this point what to do as I understand the same code works in one case but not in another and I cannot spot the problem.

  • 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-17T13:41:15+00:00Added an answer on June 17, 2026 at 1:41 pm

    You have some strings in your DenFrame.Hper and DenFrame.Vper.

    You can see this by checking the dtype or type of each element:

    In [11]: df.Hper.dtype
    Out[11]: dtype('object')
    

    Means that the numpy array could contain various types, we can see what these types are:

    In [12]: DenFrame.Hper.map(type).unique()
    Out[12]: [<type 'float'> <type 'str'>]
    

    And you could inspect which entries are strings:

    DenFrame[DenFrame.Hper.map(type) == str]
    

    Perhaps it makes sense to only include those which are floats:

    DenFrame_floats = DenFrame[(DenFrame.Hper.map(type) == float) & 
                               (DenFrame.Vper.map(type) == float)]
    

    or you could (if it’s possible) convert them to floats:

    DenFrame.Hper = DenFrame.Hper.apply(float)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a column in a pandas DataFrame that I would like to split
I have a dataframe with numerical columns. For each column I would like calculate
I have created a Pandas DataFrame df = DataFrame(index=['A','B','C'], columns=['x','y']) Now, I would like
Assume I have a pandas DataFrame with two columns, A and B. I'd like
I have two pandas dataframes: from pandas import DataFrame df1 = DataFrame({'col1':[1,2],'col2':[3,4]}) df2 =
I have a pandas DataFrame with a date column. It is not an index.
I have python pandas dataframe, in which a column contains month name. How can
I have the following pandas Dataframe: from pandas import DataFrame, MultiIndex index = MultiIndex.from_tuples(zip([21,22,23],[45,45,46]),
I'd like to create a pandas DataFrame from the following csv file: ........... EUR
I have two pandas dataframes one called orders and another one called daily_prices .

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.