我在Python中有两个数据框。我无法在一个函数中传递所需的参数。我能够在单独的函数中传递它们。假设我需要对两个数据框进行切片,并将相同的东西插入相同的索引。
我尝试将两个数据帧连接起来,以查看哪个插槽为空。
我尝试过的是
def inst(data,people):
A,B = *data
length = len(people)
for item i in range(7-length):
if not(any(data["Name","Team"][i:i+length])) and len(data)>1:
DATAFRAMEA["Name","Team"][i:i+length] = people
DATAFRAMEB["Name","Team"][i:i+length] = people
return
elif not(any(data["Name","Team"][i:i+length])) and data == DATAFRAMEA:
DATAFRAMEA["Name","Team"][i:i+length] = people
return
elif not(any(data["Name","Team"][i:i+length])) and data == DATAFRAMEB:
DATAFRAMEB["Name","Team"][i:i+length] = people
return
people = [["Lisa","Alex"],["A","D"]]
data = DATAFRAMEA+DATAFRAMEB
inst(data,people)
people = [["James"],["B"]]
inst(DATAFRAMEA,people)
数据帧A
Name Team
0 John A
1
2 Michael B
3 Joanna C
4 Sinus B
5
6
7
数据帧B
Name Team
0 John A
1 Jane D
2 Natasha B
3 Joanna C
4
5
6
7 Joshua B
如何消除对elif语句的使用?