“Python DataFrame Oblicz różnicę między kolumnami” Kod odpowiedzi

Python DataFrame Oblicz różnicę między kolumnami

import pandas as pd
  
# Create a DataFrame
df1 = { 'Name':['George','Andrea','micheal',
                'maggie','Ravi','Xien','Jalpa'],
        'score1':[62,47,55,74,32,77,86],
        'score2':[45,78,44,89,66,49,72]}
  
df1 = pd.DataFrame(df1,columns= ['Name','score1','score2'])
  
print("Given Dataframe :\n", df1)
  
# getting Difference
df1['Score_diff'] = df1['score1'] - df1['score2']
print("\nDifference of score1 and score2 :\n", df1)
Sarah Vorsselmans

Znajdź różnicę między dwiema pandasframe

# by doing outer, you will get records from both the sides.
f = df1.merge(df2,indicator = True, how='outer').loc[lambda x : x['_merge']!='both']
Out[421]: 
   A  B     _merge
1  2  3  left_only
2  3  4  left_only
3  3  4  left_only

left_unique_result = f.loc[lambda x: x['_merge'] == 'left_only']
right_unique_result = f.loc[lambda x: x['_merge'] == 'right_only']
Difficult Deer

Różnica między 2 ramami danych

df1.merge(df2,indicator = True, how='left').loc[lambda x : x['_merge']!='both']
Out[421]: 
   A  B     _merge
1  2  3  left_only
2  3  4  left_only
3  3  4  left_only
David the pythonistas

Odpowiedzi podobne do “Python DataFrame Oblicz różnicę między kolumnami”

Pytania podobne do “Python DataFrame Oblicz różnicę między kolumnami”

Więcej pokrewnych odpowiedzi na “Python DataFrame Oblicz różnicę między kolumnami” w Python

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

Przeglądaj inne języki kodu