code which returns salary for input (employee name or id)

This is the place for queries that don't fit in any of the other categories.

code which returns salary for input (employee name or id)

Postby anasanya77 » Sat Sep 24, 2016 4:58 pm

in excel, data is provided for employees' id, name and salary.have to formulate a code which will return the salary if the employee's name or id is entered.i have formulated a code, but its not working.need help.

Code:
Code: Select all
import pandas as pd
data=pd.read_excel('excel file path',sheetname=0  )
len1=len(data['salary'])
a=int(input('Enter employee id or name:'))
for row in (0,len1):
    if int(a).strip()==int(data['id'][row]).strip():
       data['salary'][row]
    elseif a.strip()==data['name'][row].strip():
       data['salary'][row]
Last edited by ichabod801 on Sat Sep 24, 2016 5:13 pm, edited 1 time in total.
Reason: code tags, first post lock
anasanya77
 
Posts: 4
Joined: Sat Sep 24, 2016 4:07 pm

Re: code which returns salary for input (employee name or id

Postby micseydel » Sat Sep 24, 2016 6:40 pm

Due to the reasons discussed here we will be moving to python-forum.io on October 1, 2016.

This forum will be locked down and no one will be able to post/edit/create threads, etc. here from thereafter. Please create an account at the new site to continue discussion.
User avatar
micseydel
 
Posts: 3000
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: code which returns salary for input (employee name or id

Postby anasanya77 » Sat Sep 24, 2016 7:47 pm

when i am running the code, in the console, its asking for the employee id or name..but, when am entering the input, say employee id or name, am not getting the salary.

Code:
Code: Select all
import pandas as pd
data=pd.read_excel('file path',sheetname=0  )
len1=len(data['salary'])
a=int(input('Enter employee id or name:'))
for row in (0,len1):
    if int(a)==int(data['id'][row]):
       data['salary'][row]
    elif a.strip()==data['name'][row].strip():
       data['salary'][row]
Last edited by Yoriz on Sat Sep 24, 2016 8:01 pm, edited 1 time in total.
Reason: Use code tags when posting code
anasanya77
 
Posts: 4
Joined: Sat Sep 24, 2016 4:07 pm

Re: code which returns salary for input (employee name or id

Postby anasanya77 » Sat Sep 24, 2016 8:54 pm

Edited code, again.Still not running.

Code:
Code: Select all
import pandas as pd
data=pd.read_excel('file path',sheetname=0  )
len1=len(data['salary'])
a=input('Enter employee id or name:')
for row in (0,len1):
    if int(a)==int(data['id'][row]):
       data['salary'][row]
    elif a.strip()==data['name'][row].strip():
       data['salary'][row]
anasanya77
 
Posts: 4
Joined: Sat Sep 24, 2016 4:07 pm

Re: code which returns salary for input (employee name or id

Postby Ofnuts » Sun Sep 25, 2016 8:18 pm

Code: Select all
      data['salary'][row]

is neither an assignment nor a print...
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987

Re: code which returns salary for input (employee name or id

Postby anasanya77 » Mon Sep 26, 2016 8:07 am

if am adding print then also i will get salary, only if employee id is entered.no result, when employee name is entered in input.
Code: Select all
import pandas as pd
data=pd.read_excel('file path',sheetname=0  )
len1=len(data['salary'])
a=input('Enter employee id or name:')
for row in (0,len1):
    if int(a)==int(data['id'][row]):
       print(data['salary'][row])
    elif a.strip()==data['name'][row].strip():
       print(data['salary'][row])
anasanya77
 
Posts: 4
Joined: Sat Sep 24, 2016 4:07 pm

Re: code which returns salary for input (employee name or id

Postby Ofnuts » Mon Sep 26, 2016 12:23 pm

anasanya77 wrote:if am adding print then also i will get salary, only if employee id is entered.no result, when employee name is entered in input.
Code: Select all
import pandas as pd
data=pd.read_excel('file path',sheetname=0  )
len1=len(data['salary'])
a=input('Enter employee id or name:')
for row in (0,len1):
    if int(a)==int(data['id'][row]):
       print(data['salary'][row])
    elif a.strip()==data['name'][row].strip():
       print(data['salary'][row])


When your code doesn't behave as you want, this is very often because your data aren't what you think. If
Code: Select all
    elif a.strip()==data['name'][row].strip():

doesn't test what you think, add some print statements to print the values of a.strip() and data['name'[row].strip()

And if one of them isn't what you think it was, figure out where it comes from, and maybe add more print statements in that area... etc...
This forum has been moved to http://python-forum.io/. See you there.
User avatar
Ofnuts
 
Posts: 2659
Joined: Thu May 14, 2015 9:46 am
Location: Paris, France, EU, Earth, Solar system, Milky Way, Local Cluster, Universe #32987440940987


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot] and 3 guests