Creating views on Pandas DataFrame Last Updated : 23 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Many times while doing data analysis we are dealing with a large data set, having a lot of attributes. All the attributes are not necessarily equally important. As a result, we want to work with only a set of columns in the dataframe. For that purpose, let's see how we can create views on the Dataframe and select only those columns that we need and leave the rest. For link to the CSV file used in the code, click here. Solution #1: A set of columns in the DataFrame can be selected by dropping all those columns which are not needed. Python3 1== # importing pandas as pd import pandas as pd # Reading the csv file df = pd.read_csv("nba.csv") # Print the dataframe print(df) Output : Now we will select all columns except the first three columns. Python3 # drop the first three columns df.drop(df.columns[[0, 1, 2]], axis = 1) Output : We can also use the names of the column to be dropped. Python3 # drop the 'Name', 'Team' and 'Number' columns df.drop(['Name', 'Team', 'Number'], axis = 1) Output : Solution #2 : We can individually select all those columns which we need and leave out the rest. Python3 1== # importing pandas as pd import pandas as pd # Reading the csv file df = pd.read_csv("nba.csv") # select the first three columns # and store the result in a new dataframe df_copy = df.iloc[:, 0:3] # Print the new DataFrame df_copy Output : We can also select the columns in a random manner by passing a list to the DataFrame.iloc attribute. Python3 # select the first, third and sixth columns # and store the result in a new dataframe # The numbering of columns begins from 0 df_copy = df.iloc[:, [0, 2, 5]] # Print the new DataFrame df_copy Output : Alternatively, we can also name the columns that we want to select. Python3 # Select the below listed columns df_copy = df[['Name', 'Number', 'College']] # Print the new DataFrame df_copy Output : Comment More infoAdvertise with us Next Article Creating a Pandas DataFrame S Shubham__Ranjan Follow Improve Article Tags : Pandas Python-pandas Python pandas-dataFrame AI-ML-DS With Python Similar Reads Creating a Pandas DataFrame Pandas DataFrame comes is a powerful tool that allows us to store and manipulate data in a structured way, similar to an Excel spreadsheet or a SQL table. A DataFrame is similar to a table with rows and columns. It helps in handling large amounts of data, performing calculations, filtering informati 2 min read Adding New Variable to Pandas DataFrame In this article let's learn how to add a new variable to pandas DataFrame using the assign() function and square brackets. Pandas is a Python package that offers various data structures and operations for manipulating numerical data and time series. It is mainly popular for importing and analyzing d 3 min read Create empty dataframe in Pandas The Pandas Dataframe is a structure that has data in the 2D format and labels with it. DataFrames are widely used in data science, machine learning, and other such places. DataFrames are the same as SQL tables or Excel sheets but these are faster in use.Empty DataFrame could be created with the help 1 min read Creating Pandas dataframe using list of lists In this article, we will explore the Creating Pandas data frame using a list of lists. A Pandas DataFrame is a versatile 2-dimensional labeled data structure with columns that can contain different data types. It is widely utilized as one of the most common objects in the Pandas library. There are v 4 min read Convert JSON to Pandas DataFrame When working with data, it's common to encounter JSON (JavaScript Object Notation) files, which are widely used for storing and exchanging data. Pandas, a powerful data manipulation library in Python, provides a convenient way to convert JSON data into a Pandas data frame. In this article, we'll exp 4 min read Different ways to create Pandas Dataframe It is the most commonly used Pandas object. The pd.DataFrame() function is used to create a DataFrame in Pandas. There are several ways to create a Pandas Dataframe in Python.Example: Creating a DataFrame from a DictionaryPythonimport pandas as pd # initialize data of lists. data = {'Name': ['Tom', 7 min read Like