Pawandeep Kaur

Pawandeep Kaur

19 Articles Published

Articles by Pawandeep Kaur

19 articles

How to plot a graph in Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 64K+ Views

Graphs in Python can be plotted by using the Matplotlib library. Matplotlib library is mainly used for graph plotting and provides inbuilt functions to draw line graphs, bar graphs, histograms, and pie charts. You need to install matplotlib before using it to plot graphs ? pip install matplotlib Plot a Line Graph We will plot a simple line graph using matplotlib. The following steps are involved in plotting a line ? Import matplotlib.pyplot Specify the x-coordinates and y-coordinates of the line Plot the specified points using .plot() function Name the x-axis and ...

Read More

Explain and show the use of UNION in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 1K+ Views

The UNION statement combines results from two or more SELECT queries, automatically removing duplicate rows. This is useful when you need to retrieve data from multiple tables with similar structure. Syntax SELECT column_name FROM table1 UNION SELECT column_name FROM table2 Requirements for UNION To perform UNION operations, the following conditions must be met ? Both SELECT statements must return the same number of columns Corresponding columns must have compatible data types Columns must be in the same order in both queries Sample Tables Let's work with two sample tables ...

Read More

How to show all the tables present in the database and server in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 18K+ Views

When working with MySQL databases in Python, you may need to retrieve a list of all tables present in a specific database or across the entire server. This can be accomplished using SQL commands like SHOW TABLES and querying the information_schema. Syntax To show tables present in a database − SHOW TABLES To show tables present across the server − SELECT table_name FROM information_schema.tables Required Steps Import MySQL connector Establish connection using connect() Create cursor object using cursor() method Execute the appropriate SQL query Fetch and display results ...

Read More

How to count SQL table columns using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 3K+ Views

Counting the number of columns in a SQL table is a common database administration task. Python provides an efficient way to do this using the MySQL connector and the information_schema.columns system table. Syntax The SQL query to count columns uses the information_schema.columns table ? SELECT COUNT(*) FROM information_schema.columns WHERE table_name='your_table_name' Steps to Count Columns Import MySQL connector Establish connection with the database Create cursor object using cursor() method Execute the column count query Fetch and display results Close the connection Sample Table Structure Let's assume we have a table ...

Read More

How can you test if some record exists or not in a MySQL table using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 9K+ Views

We may at times need to check if a particular record exists in a MySQL table. This can be done using the EXISTS statement or by checking if a query returns any rows. The EXISTS statement returns true if the following subquery returns one or more records. Syntax SELECT * FROM table_name WHERE EXISTS(sub_query) The subquery if returns one or more rows, the EXISTS will return true. Steps to Check if a Record Exists Import MySQL connector Establish connection with the connector using connect() Create the cursor object using cursor() method Create ...

Read More

How to add a column to a MySQL table in Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 5K+ Views

Adding new columns to existing MySQL tables is a common database operation. This can be accomplished in Python using the ALTER TABLE command with the MySQL connector library. Syntax ALTER TABLE table_name ADD new_column_name column_definition [FIRST | AFTER existing_column] Here, table_name refers to the name of the table, new_column_name refers to the name of the column to be added, and column_definition refers to the datatype of the column. The FIRST and AFTER clauses are optional and specify the position where the new column should be added. By default, the new column is inserted at ...

Read More

How to perform arithmetic across columns of a MySQL table using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 755 Views

Performing arithmetic operations across columns in a MySQL table using Python is a common task in data analysis. You can add, subtract, multiply, divide, or find the modulus of numeric columns using SQL queries executed through Python's MySQL connector. Syntax The basic syntax for arithmetic operations in SQL is: SELECT column1 + column2 AS result FROM table_name; Replace + with -, *, /, or % for subtraction, multiplication, division, or modulus operations respectively. Steps to Perform Arithmetic Operations Import MySQL connector Establish connection using connect() Create cursor object using cursor() method ...

Read More

How to add comment to column in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 664 Views

A comment is a readable explanation that describes the purpose or function of a database column. Comments help other developers understand what data a column stores and how it should be used. In MySQL, you can add comments to table columns using the ALTER TABLE statement with the COMMENT clause. This is particularly useful for documenting complex database schemas. Syntax ALTER TABLE table_name MODIFY column_name column_definition COMMENT "your_comment" Here, table_name specifies the table name, column_name and column_definition specify the column name and datatype, and your_comment is the descriptive text you want to add. ...

Read More

How to get the id after INSERT into MySQL database using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 9K+ Views

When inserting data into a MySQL database using Python, you often need to retrieve the ID of the newly inserted record. This is particularly useful for linking records across multiple tables or for tracking purposes. The lastrowid attribute of the cursor object returns the auto-generated ID of the last INSERT operation. This works only when certain conditions are met ? Prerequisites The ID column must be the primary key in the table The ID column must be auto-incremented The table must use a storage engine that supports auto-increment (like InnoDB or MyISAM) Syntax ...

Read More

Explain the use of COUNT() AND SUM() in MySQL using Python?

Pawandeep Kaur
Pawandeep Kaur
Updated on 25-Mar-2026 3K+ Views

The COUNT() and SUM() functions are MySQL aggregate functions used to perform arithmetic operations on column values. These functions are essential for data analysis and reporting in database applications. The COUNT() function returns the number of rows that satisfy a specified condition, while the SUM() function calculates the total of numerical values in a column, ignoring NULL values. Syntax COUNT() Function: SELECT COUNT(column_name) FROM table_name WHERE condition SUM() Function: SELECT SUM(column_name) FROM table_name WHERE condition Steps to Use COUNT() and SUM() with MySQL in Python ...

Read More
Showing 1–10 of 19 articles
« Prev 1 2 Next »
Advertisements