How to select rows and columns in pandas (Python)

Πως να επιλέγετε γραμμές και στήλες με τη βιβλιοθήκη 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’,’XL’,’Extra Large’,4,’variation’,0,0],



[‘A0003′,’BLACK’,’XL’,’Extra Large’,7,’variation’,0,0],



[‘A0002′,’BLACK’,’XL’,’Extra Large’,10,’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)



# dataframe with defined column names

df = pd.DataFrame(data, columns=[‘parent’, ‘color’, ‘size’, ‘size_desc’, ‘order’, ‘type’, ‘quantity’,’price’])


print(‘–dataframe with defined column names—————————————‘)


# end of code —————————————————————————————–

If you want to see more ways to select rows and columns in pandas (Python), read my code (Version 2) in  html format.

Comments are closed.

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.