Read a Specific Column from Excel in Python

excel
python

#1

Hi,

I have a function say

def excelsqrtfile(k):
  if(k>0):
    result = m.sqrt(x)
    print(result)
  else:
    result = 0
  return result

I need to apply this function to a specific column in Excel sheet.
I have a dataframe df

I am calling the function like below.

df1["sqr"]=excelsqrtfile(df1.dummy)

Error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Any Help would be appreciated.

Thanks,


#2

Have got the answer
Thanks


#3

Hi @sachin123456,

Could you share how you resolved the issue ? So that if anyone in future faces a similar problem would know how to solve.


#4

@AishwaryaSingh Here is the solution and it is working as well
I am calling the function in this way -

for x in df1['dummy']:
    print( excelsqrtfile (x))

Thanks,
Sachin


#5

Here is the another one - to have the values store in dataframe

for x in df1['dummy']:
    df1["sqr"]=excelsqrtfile(x)

#6

Thanks !