“Podzień Python” Kod odpowiedzi

Pokrój danych według listy wartości

In [1]: df = pd.DataFrame({'A': [5,6,3,4], 'B': [1,2,3,5]})

In [2]: df
Out[2]:
   A  B
0  5  1
1  6  2
2  3  3
3  4  5

In [3]: df[df['A'].isin([3, 6])]
Out[3]:
   A  B
1  6  2
2  3  3
Busy Boar

Python - Rzębia DataFrame według liczby wierszy

df.iloc[[1, 5]]                                               # Get rows 1 and 5
df.iloc[1:6]                                                  # Get rows 1 to 5 inclusive
df.iloc[[1, 5], df.columns.get_loc('Shop')]                   # Get only specific column
df.iloc[[1, 5], df.columns.get_indexer(['Shop', 'Category'])] # Get multiple columns
Andrea Perlato

Jak sprawdzić, czy lista jest podzbiorem innej listy

if(all(x in test_list for x in sub_list)): 
  flag = True
Open Opossum

Wybierz kolumny, które można uwzględnić w nowej ramce danych w Python

new = old.filter(['A','B','D'], axis=1)
Fantastic Fly

podzbiór w Python

    smallSet = {'a', 'b'}
    superSet = {'a', 'b', 'c'}

    print(smallSet.issubset(superSet)) # This will return True
    print(superSet.issubset(smallSet)) # This will return False
CompSciGeek

Podzień Python

n,su = map(int,input().split())
A = list(map(int,input().split()[:n]))
s = []
for i in range(0,len(A)+1):
    for j in range(i+1,len(A)+1):
        s.append(A[i:j])
        
for k in s:
    if sum(k) == su:
        f = 1
        break
if f == 1:
    print("TRUE")  
else:
    print("FALSE")
Voleti Nagendra kumar

Odpowiedzi podobne do “Podzień Python”

Pytania podobne do “Podzień Python”

Więcej pokrewnych odpowiedzi na “Podzień Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu