Python Articles

Page 139 of 855

Python Program to Interchange Elements of First and Last in a Matrix Across Rows

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 237 Views

A matrix is a set of numbers arranged in rows and columns format. In Python, a matrix can be created using nested lists or NumPy arrays. This tutorial demonstrates how to interchange the first and last rows of a matrix. Input Output Scenarios Let's look at examples of interchanging first and last rows in different matrices ? Input matrix: [1, 2, 3] [4, 5, 6] [7, 8, 9] Output matrix: [7, 8, 9] [4, 5, 6] [1, 2, 3] For matrices with unequal row lengths ? Input matrix: ...

Read More

How do I create a constant in Python?

Gireesha Devara
Gireesha Devara
Updated on 27-Mar-2026 2K+ Views

In Python, there's no built-in data type for constants like other programming languages. However, Python follows naming conventions and provides several approaches to create constants that signal to other developers that a value shouldn't be changed. Built-in Constants in Python Python has six built-in constants: False, True, None, NotImplemented, Ellipsis (...), and __debug__. These cannot be reassigned ? # Trying to reassign a built-in constant raises SyntaxError try: False = 100 except SyntaxError as e: print(f"Error: {e}") File "", line 2 ...

Read More

How to display notnull rows and columns in a Python dataframe?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 7K+ Views

In this tutorial, we will learn how to display notnull rows and columns in a Python dataframe using the Pandas library. A dataframe is a two-dimensional labeled data structure that can hold multiple columns of potentially different data types such as integer, float, string, etc. Using dropna() Method The dropna() method returns a dataframe with all rows and columns containing null values removed from the original dataframe ? Syntax df.dropna() Example In this example, we create a sample dataframe with some null values and use dropna() to remove rows containing any null ...

Read More

How to display most frequent value in a Pandas series?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 9K+ Views

In this tutorial, we will learn how to display the most frequent value in a Pandas series. A Pandas Series is a one-dimensional labeled data structure that can hold different data types like integers, floats, and strings. The most frequent value is also known as the mode of the data. Using value_counts() Method The value_counts() method returns a Series with counts of each unique value sorted in descending order. The most frequent value appears first. Syntax counts = series.value_counts() most_frequent = counts.index[0] Example with Numbers Let's find the most frequent number in ...

Read More

How to delete only one row in csv with Python?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 23K+ Views

In this tutorial, we will learn to delete only one row in CSV with Python using the Pandas library. Pandas is an open-source library for data analysis that provides several functionalities to perform operations on data sets. We will use the drop() method to delete a row from any CSV file. This tutorial illustrates three different approaches to delete a row from CSV files using the same method. Syntax Here's the basic syntax to delete a row from a CSV file ? import pandas as pd # Read CSV file df = pd.read_csv("filename.csv") ...

Read More

How to make Violinpot with data points in Seaborn?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 474 Views

In data analysis and visualization, violin plots are powerful tools for visualizing the distribution of numeric data across different categories. Unlike box plots, violin plots show the full distribution shape by combining a box plot with a kernel density estimation. In this tutorial, we will learn how to create violin plots with data points using Seaborn. To create violin plots in Seaborn, we need to import the necessary libraries: Seaborn for plotting, Matplotlib for customization, and Pandas for data manipulation. Syntax The basic syntax for creating a violin plot with data points is − import ...

Read More

How to delete only empty folders in Python?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 3K+ Views

In this tutorial, we will learn how to delete only empty folders in Python. As you delete files or uninstall programs, empty folders might build up over time, but they can be challenging to locate and manually eliminate. Fortunately, Python offers a quick and effective way to delete empty directories automatically. Approach We can use the built-in os module to identify and delete empty folders using Python. Here's the basic workflow of how we can achieve this ? Use os.walk() to traverse the file system recursively, starting at a given root directory. For each directory encountered ...

Read More

Which is Better to Learn Machine Learning: C++, Python, or R?

Devang Delvadiya
Devang Delvadiya
Updated on 27-Mar-2026 435 Views

Machine learning (ML) is the study of computer algorithms that learn patterns from data without explicit programming. When choosing a programming language for ML, three popular options are C++, Python, and R. Each has distinct advantages depending on your goals and experience level. What is Machine Learning? Machine Learning enables computers to identify patterns and make predictions by processing large datasets. It's widely used in healthcare, finance, e-commerce, manufacturing, and transportation. Tech giants like Google, Apple, and Microsoft rely heavily on ML to enhance user experiences and optimize operations. C++ for Machine Learning C++ is a ...

Read More

How to manually add a legend with a color box on a Matplotlib figure?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 4K+ Views

Matplotlib is a popular data visualization library in Python known for its flexibility and high-quality visualizations. By following this tutorial, you will learn how to create a legend with a color box on your Matplotlib figure, making your visualizations more informative and visually appealing. A legend is a key that labels the elements in our plot with different colors, markers, or lines. By adding a legend, we can understand the data being presented and make it easier for the audience to interpret our visualizations. Syntax To manually add a legend with a color box on a Matplotlib ...

Read More

How to manually add a legend color and legend font size on a plotly figure in Python?

Manthan Ghasadiya
Manthan Ghasadiya
Updated on 27-Mar-2026 2K+ Views

This tutorial explains how to manually customize legend text color and font size on a Plotly figure using Python. Plotly is a powerful data visualization library that creates interactive charts and graphs. While Plotly provides default legend settings, you may need to customize the legend appearance to match your specific design requirements. Syntax Use Plotly's update_layout() method with the legend_font_color and legend_font_size parameters to customize legend appearance ? fig = px.scatter(df, x="x_column", y="y_column", color="category_column") # Set legend font color fig.update_layout(legend_font_color='red') # Set legend font size fig.update_layout(legend_font_size=14) # Or combine both parameters ...

Read More
Showing 1381–1390 of 8,549 articles
« Prev 1 137 138 139 140 141 855 Next »
Advertisements