Compare Headers of Two pandas DataFrames in Python (3 Examples) | intersection & difference Function

Veröffentlicht am: 29 Juni 2022
auf dem Kanal: Statistics Globe
245
4

How to compare the headers of two pandas DataFrames in the Python programming language. More details: https://statisticsglobe.com/compare-h...
Python code of this video:

import pandas as pd # Import pandas library

data1 = pd.DataFrame({'x1':range(0, 6), # Create first pandas DataFrame
'x2':['a', 'b', 'c', 'd', 'e', 'f'],
'x3':range(10, 16),
'x4':['a', 'a', 'a', 'b', 'b', 'b'],
'x5':range(100, 106)})
print(data1) # Print first pandas DataFrame

data2 = pd.DataFrame({'x1':range(25, 30), # Create second pandas DataFrame
'x2':['x', 'y', 'z', 'z', 'x'],
'x5':range(30, 25, - 1),
'x6':range(50, 45, - 1)})
print(data2) # Print second pandas DataFrame

print(data1.columns.intersection(data2.columns)) # Apply intersection function
Index(['x1', 'x2', 'x5'], dtype='object')

print(data1.columns.difference(data2.columns)) # Apply difference function
Index(['x3', 'x4'], dtype='object')

print(data2.columns.difference(data1.columns)) # Apply difference function
Index(['x6'], dtype='object')

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – Group for Discussions & Questions:   / statisticsglobe  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – Group for Discussions & Questions:   / 12555223  
Twitter:   / joachimschork  

Music by bensound.com


Auf dieser Seite können Sie das Online-Video Compare Headers of Two pandas DataFrames in Python (3 Examples) | intersection & difference Function mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Statistics Globe 29 Juni 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 245 Mal angesehen und es wurde von 4 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!