Count number of columns of a Pandas DataFrame Last Updated : 26 Jul, 2020 Comments Improve Suggest changes Like Article Like Report Let's discuss how to count the number of columns of a Pandas DataFrame. Lets first make a dataframe. Example: Python3 # Import Required Libraries import pandas as pd import numpy as np # Create a dictionary for the dataframe dict = {'Name': ['Sukritin', 'Sumit Tyagi', 'Akriti Goel', 'Sanskriti', 'Abhishek Jain'], 'Age': [22, 20, np.inf, -np.inf, 22], 'Marks': [90, 84, 33, 87, 82]} # Converting Dictionary to Pandas Dataframe df = pd.DataFrame(dict) # Print Dataframe df Output: Method 1: Using shape property Shape property returns the tuple representing the shape of the DataFrame. The first index consists of the number of rows and the second index consist of the number of columns. Python3 # Getting shape of the df shape = df.shape # Printing Number of columns print('Number of columns :', shape[1]) Output: Method 2: Using columns property The columns property of the Pandas DataFrame return the list of columns and calculating the length of the list of columns, we can get the number of columns in the df. Python3 # Getting the list of columns col = df.columns # Printing Number of columns print('Number of columns :', len(col)) Output: Method 3: Casting DataFrame to list Like the columns property, typecasting DataFrame to the list returns the list of the name of the columns. Python3 # Typecasting df to list df_list = list(df) # Printing Number of columns print('Number of columns :', len(df_list)) Output: Method 4: Using info() method of DataFrame This methods prints a concise summary of the DataFrame. info() method prints information about the DataFrame including dtypes of columns and index, memory usage, number of columns, etc. Python3 # Printing info of df df.info() Output: Comment More infoAdvertise with us Next Article Count number of columns of a Pandas DataFrame S sukritinpal Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame pandas-dataframe-program Practice Tags : python Similar Reads Count the number of rows and columns of Pandas dataframe In this article, we'll see how we can get the count of the total number of rows and columns in a Pandas DataFrame. There are different methods by which we can do this. Let's see all these methods with the help of examples. Example 1: We can use the dataframe.shape to get the count of rows and column 2 min read Count number of rows and columns in Pandas dataframe In Pandas understanding number of rows and columns in a DataFrame is important for knowing structure of our dataset. Whether we're cleaning the data, performing calculations or visualizing results finding shape of the DataFrame is one of the initial steps. In this article, we'll explore various ways 3 min read Count Frequency of Columns in Pandas DataFrame When working with data in Pandas counting how often each value appears in a column is one of the first steps to explore our dataset. This helps you understand distribution of data and identify patterns. Now weâll explore various ways to calculate frequency counts for a column in a Pandas DataFrame.1 2 min read How to Count Distinct Values of a Pandas Dataframe Column? Let's discuss how to count distinct values of a Pandas DataFrame column. Using pandas.unique()You can use pd.unique()to get all unique values in a column. To count them, apply len()to the result. This method is useful when you want distinct values and their count.Pythonimport pandas as pd # Create D 4 min read Get number of rows and columns of PySpark dataframe In this article, we will discuss how to get the number of rows and the number of columns of a PySpark dataframe. For finding the number of rows and number of columns we will use count() and columns() with len() function respectively. df.count(): This function is used to extract number of rows from t 6 min read Convert a Dataframe Column to Integer in Pandas Converting DataFrame columns to the correct data type is important especially when numeric values are mistakenly stored as strings. Let's learn how to efficiently convert a column to an integer in a Pandas DataFrameConvert DataFrame Column to Integer - using astype() Methodastype() method is simple 3 min read Get the number of rows and number of columns in Pandas Dataframe Pandas provide data analysts a variety of pre-defined functions to Get the number of rows and columns in a data frame. In this article, we will learn about the syntax and implementation of few such functions. Method 1: Using df.axes() Method axes() method in pandas allows to get the number of rows a 3 min read Show all columns of Pandas DataFrame Pandas sometimes hides some columns by default if the DataFrame is too wide. To view all the columns in a DataFrame pandas provides a simple way to change the display settings using the pd.set_option() function. This function allow you to control how many rows or columns are displayed in the output. 2 min read Get the datatypes of columns of a Pandas DataFrame Let us see how to get the datatypes of columns in a Pandas DataFrame. TO get the datatypes, we will be using the dtype() and the type() function.Example 1 :Â Â python # importing the module import pandas as pd # creating a DataFrame dictionary = {'Names':['Simon', 'Josh', 'Amen', 'Habby', 'Jonathan', 2 min read How to convert index in a column of the Pandas dataframe? Each row in a dataframe (i.e level=0) has an index value i.e value from 0 to n-1 index location and there are many ways to convert these index values into a column in a pandas dataframe. First, let's create a Pandas dataframe. Here, we will create a Pandas dataframe regarding student's marks in a pa 4 min read Like