Count SQL Table Column Using Python Last Updated : 23 Dec, 2020 Comments Improve Suggest changes Like Article Like Report Prerequisite: Python: MySQL Create Table In this article, we are going to see how to count the table column of a MySQL Table Using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an API in python for communicating with a MySQL database. We are going to use geeks(Database name) database and table describing the salary. Approach: Import module.Make a connection request with the database.Create an object for the database cursor.Execute the following MySQL query: SELECT count(*) AS New_column_name FROM information_schema.columns where table_name = 'Table_name'; Example 1: In this example we are using this database with the following query; Python3 # Establish connection to MySQL database import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", password="root123", database="geeks" ) # Create a cursor object mycursor = mydb.cursor() # Execute the query query = "SELECT count(*) AS New_column_name FROM information_schema.columns where table_name = 'Persons';" mycursor.execute(query) myresult = mycursor.fetchall() print(myresult[-1][-1]) # Close database connection mydb.close() Output; 5 Example 2: In this example we are using this database with the following query; Python3 # Establish connection to MySQL database import mysql.connector mydb = mysql.connector.connect( host="localhost", user="root", password="root123", database="geeks" ) # Create a cursor object mycursor = mydb.cursor() # Execute the query query = "SELECT count(*) AS New_column_name FROM information_schema.columns where table_name = 'Salary';" mycursor.execute(query) myresult = mycursor.fetchall() print(myresult[-1][-1]) # Close database connection mydb.close() Output: 2 Comment More infoAdvertise with us Next Article Count SQL Table Column Using Python kumar_satyam Follow Improve Article Tags : Python Python-mySQL Practice Tags : python Similar Reads How to Find Duplicate Values in a SQL Table using Python? MySQL server is an open-source relational database management system that is a major support for web-based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. In order to access MySQL databases from a w 3 min read Python SQLAlchemy - func.count with filter In this article, we are going to see how to perform filter operation with count function in SQLAlchemy against a PostgreSQL database in python Count with filter operations is performed in different methods using different functions. Such kinds of mathematical operations are database-dependent. In Po 3 min read How to Count the Number of Rows of a Given SQLite Table using Python? In this article, we will discuss how we can count the number of rows of a given SQLite Table using Python. We will be using the cursor_obj.fetchall() method to do the same. This method fetches all the rows of a query result. It returns all the rows as a list of tuples. An empty list is returned if t 2 min read How to Compute the Sum of All Rows of a Column of a MySQL Table Using Python? MySQL server is an open-source relational database management system that is a major support for web-based applications. Databases and related tables are the main component of many websites and applications as the data is stored and exchanged over the web. In order to access MySQL databases from a w 2 min read seaborn.countplot() in Python seaborn.countplot() is a function in the Seaborn library in Python used to display the counts of observations in categorical data. It shows the distribution of a single categorical variable or the relationship between two categorical variables by creating a bar plot. Example:Pythonimport seaborn as 8 min read How to Add a Column to a MySQL Table in Python? Prerequisite: Python: MySQL Create Table Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an API in python for communicating with a MySQL database.  ALTER statemen 4 min read Python SQLAlchemy - Get column names dynamically In this article, we are going to see how to dynamically get the column names of a table in SQLAlchemy using Python. Used database for demonstration:Student table So, our student table has 5 columns namely sno, name, dob, class, and section, and our task is to fetch all these column names in our Pyth 2 min read Python | Pandas Series.value_counts() Pandas is one of the most widely used library for data handling and analysis. It simplifies many data manipulation tasks especially when working with tabular data. In this article, we'll explore the Series.value_counts() function in Pandas which helps you quickly count the frequency of unique values 2 min read Python collections Counter Counters are a subclass of the dict class in Python collections module. They are used to count the occurrences of elements in an iterable or to count the frequency of items in a mapping. Counters provide a clean and efficient way to tally up elements and perform various operations related to countin 4 min read Like