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

Pubblicato il: 29 giugno 2022
sul canale di: 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


In questa pagina del sito puoi guardare il video online Compare Headers of Two pandas DataFrames in Python (3 Examples) | intersection & difference Function della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Statistics Globe 29 giugno 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 245 volte e gli è piaciuto 4 spettatori. Buona visione!