How to Extract First & Last N Columns from pandas DataFrame in Python (2 Examples) | iloc Attribute

Pubblicato il: 11 maggio 2022
sul canale di: Statistics Globe
880
8

How to return the first and last N columns from a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/extract-f...
Python code of this video:

import pandas as pd # Load pandas library

data = pd.DataFrame({'x1':range(10, 15), # Create pandas DataFrame
'x2':range(0, 5),
'x3':['a', 'b', 'c', 'd', 'e'],
'x4':range(8, 3, - 1),
'x5':['x', 'y', 'x', 'y', 'x']})
print(data) # Print pandas DataFrame

data_first_n = data.iloc[:, :3] # Select first columns
print(data_first_n) # Print first columns

data_last_n = data.iloc[:, 3:] # Select last columns
print(data_last_n) # Print last columns

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 How to Extract First & Last N Columns from pandas DataFrame in Python (2 Examples) | iloc Attribute della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Statistics Globe 11 maggio 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 880 volte e gli è piaciuto 8 spettatori. Buona visione!