How to Do Scatter Plots in Python

This tutorial shows how to use Pandas, Matplotlib, and Seaborn for scatter plots in Python with examples, codes, and charts. There are two methods of doing scatter plots in Python. The following shows the core syntax. Pandas: df.plot (kind=”scatter”, x=”column_x”, y=”column_y”) Seaborn: sns.lmplot (x=”column_x”, y=”column_y”, data=df, fit_reg=True) Example 1: Use Pandas for scatter plots in … Read more

Plot Histogram in Python

Introduction We can use hist() in Matplotlib, pandas, and seaborn to plot histograms in Python. The following is the basic syntax of plotting histogram using these 3 different modules. Method 1: Using matplotlib plt.hist(data,bins=’auto’) Method 2: Using pandas pd.hist() Method 3: Using seaborn sns.histplot(data=dataset, x=’column_name’) Sample Data for Histogram We generate a randon sample of … Read more

How to Calculate Mean in Python (NumPy)

This short tutorial shows how you can calculate mean in Python using NumPy. First, we generate the random data with mean of 5 and standard deviation (SD) of 1. Then, you can use the numpy is mean() function. As you can see, the mean of the sample is close to 5. 4.943504497663466 Regarding of how … Read more

Generate Sample of Normal Distribution in Python NumPy

This tutorial shows how to generate a sample of normal distrubution using NumPy in Python. The following shows syntax of two methods. Method 1: It can change the default values (Default: mu=0 and sd=1). np.random.normal(mu=0, sigma=1, size) Method 2: It can only generate numbers of standard normal (mu=0 and sd=1). But, it can have different … Read more

How to Plot Bar Charts in Python

This tutorial will show how you can plot bar charts using Python with detailed examples. Similar to line charts, bar charts show the relationship between X (on x-asix) and Y (on Y-asix). I will first use the same data as in line charts to illustrate how to plot bar charts. Then, I will use another … Read more

How to Plot Line Charts in Python

Line charts are typically used to show the overall trend of a certain topic. For instance, you can use a line chart to show the overall price movement of a stock or people’s interest in a certain topic or object. The following shows the core syntax to plot line charts in Python, including Seaborn, matplotlib, … Read more

What are Class, Object, and Method in Python?

A class is a user-defined prototype, from which objects can be created. Classes can bundle data and functions together. An object is an instance of a class. When an object is created, the class is said to be instantiated.  How to define a simple class? The following is an example of defining a class in … Read more

Python Booleans

What are Booleans? Booleans are two opposite values: either True or False. The tutorial provides examples about writing Boolean statements in Python.