Skip to content

Python code snippet – How to pick out separate columns from the pandas dataframe object?

df1 = df.iloc[:, 0:2] # If you want to do it by index. Remember that Python does not slice inclusive of the ending index.
df1 = df[['a', 'b']] ## if you want to do it b nae
See also  Python code snippet - How to convert adjacency matrix to adjacency list?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.