Tag

pandas

Browsing

Πως να επιλέγετε γραμμές και στήλες με τη βιβλιοθήκη pandas της γλώσσας προγραμματισμού Python See below the data and the code for the result shown on image . . . How to select rows and columns in pandas # Credit : Trifonas Papadopoulos, Oct 4th, 2022, Version 2.0 # start of code —————————————————————————————– import pandas as pd import numpy as np # data data = [[‘A0001′,”,”,”,0,’variable’,0,0], [‘A0001′,’WHITE’,’S’,’Small’,1,’variation’,0,0], [‘A0001′,’WHITE’,’M’,’Medium’,2,’variation’,0,0], [‘A0001′,’WHITE’,’L’,’Large’,3,’variation’,0,0], [‘A0001′,’WHITE’,’XL’,’Extra Large’,4,’variation’,0,0], [‘A0001′,’BLACK’,’L’,’Large’,5,’variation’,0,0], [‘A0003′,”,”,”,6,’variable’,0,0], [‘A0003′,’BLACK’,’XL’,’Extra Large’,7,’variation’,0,0], [‘A0002′,”,”,”,8,’variable’,0,0], [‘A0002′,’BLACK’,’L’,’Large’,9,’variation’,0,0], [‘A0002′,’BLACK’,’XL’,’Extra Large’,10,’variation’,0,0], [‘A0004′,”,”,”,12,’variable’,0,0], [‘A0004′,’WHITE’,’S’,’Small’,12,’variation’,0,0], [‘A0004′,’RED’,’S’,’Small’,13,’variation’,0,0], [‘A0004′,’RED’,’M’,’Medium’,14,’variation’,0,0], [‘A0001′,’WHITE’,’XXL’,’2 Extra Large’,15,’variation’,0,0], ] # print list of columns print(‘–list of columns———————————————————–‘) cols = list(df.columns.values) print(cols) # dataframe with defined column names df = pd.DataFrame(data, columns=[‘parent’, ‘color’, ‘size’, ‘size_desc’, ‘order’, ‘type’, ‘quantity’,’price’]) print(”) print(‘–dataframe with defined column names—————————————‘) print(df) # end of code —————————————————————————————– If you want to see more ways to select rows and columns in pandas (Python), read my code (Version…

Pin It

By continuing to use the site, you agree to the use of cookies. / Συνεχίζοντας να χρησιμοποιείτε την ιστοσελίδα, συμφωνείτε με τη χρήση των cookies. more information / περισσότερες πληροφορίες

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close