【发布时间】:2017-02-09 12:36:31
【问题描述】:
我正在尝试编写一个脚本来检查经理编号是否与员工编号匹配。它将继续向下列,直到检查所有数字。 完成后,它会打印出匹配或不匹配的列表。
[In:]
import pandas as pd
#reading in csv file to Data Frame
employeeData = pd.read_csv("C:/Users/Desktop/EmployeeList.csv")
#creatig a Data Frame
dataF = pd.DataFrame(employeeData);
#empty list where instances of T/F will be stored
booleans = [];
#256 manager numbers + 1896 empty rows
managers = pd.Series(employeeData['Manager ID Number']
#Edit Forgot to include this line
condition = managers.equals(merge['Employee ID'])
#check each row of employee data. 2153 rows of Employee Numbers
for index, row in employeeData.iterrows():
#Check every single Manager number for a match
for index, row in managers.iteritems():
if condition:
booleans.append(True)
print("Something matched!")
else:
print("Didn't match!"
booleans.append(False)
#A length of all booleans is printed.
print(len(booleans))
[Out:] Actual
"Didn't match!" x 2153 times. (number of employees in list)
[Out:] Desired:
"Something matched!"
"Didn't match!"
"Something matched!"
"Something matched!"
"Didn't match!"
"Something matched!".... to line 2153
我的问题是索引计数似乎不会下降。它只会输出与第一个数字不匹配的数百次。我想将行位置向下移动,以便根据经理列表检查所有员工编号。有些经理的员工比其他经理多,所以我必须检查每一个!(256)我很尴尬地说我已经被这个问题困住了很长一段时间。 python新手,所以任何提示将不胜感激
【问题讨论】:
标签: python excel python-3.x csv pandas