Showing posts with label dataframe. Show all posts
Showing posts with label dataframe. Show all posts

How to view all column names in Pandas DataFrame?

It is often annoying if you want to see all columns in your Pandas DataFrame. Set the following to display all columns.

pd.set_option("display.max_columns", None)

What is the difference between iloc, loc, ix for Pandas DataFrame?

  • loc gets rows (or columns) with particular labels from the index. 


# delete columns which ends with column name "Name"
df1 = df.loc[:, ~df.columns.str.endswith('Name')]
# delete columns which contain "Name" in column name
df1 = df.loc[:, ~df.columns.str.contains('Name')]
  • iloc gets rows (or columns) at particular positions in the index (so it only takes integers).

  • ix usually tries to behave like loc but falls back to behaving like iloc if a label is not present in the index.