List of Topics:
Location Research Breakthrough Possible @S-Logix pro@slogix.in

Office Address

Social List

How to Plot Basic Visualization Using Pandas in Python

Basic Visualization Using Pandas

Condition for Basic Visualization Using Pandas in Python

  • Description:
    Pandas provides built-in data visualization capabilities via the plot() method, which is based on Matplotlib. This allows for quick and simple creation of basic plots directly from a DataFrame or Series.

    Pandas supports various types of plots such as line, bar, histogram, scatter, and box plots.
Step-by-Step Process
  • Import Libraries:
    Import pandas and matplotlib.pyplot.
  • Load or Create Data:
    Prepare the dataset as a DataFrame or Series.
  • Choose the Plot Type:
    Use the .plot() method with the appropriate kind argument to specify the type of plot.
  • Customize the Plot:
    Add titles, labels, legends, or modify styles.
  • Display the Plot:
    Use plt.show() to render the visualization.
Sample Source Code
  • # Code for basic visualization

    import pandas as pd
    import matplotlib.pyplot as plt

    data = {
    'Month': ['Jan', 'Feb', 'Mar', 'Apr', 'May'],
    'Sales': [200, 300, 250, 400, 350],
    'Profit': [50, 80, 60, 100, 90]
    }
    df = pd.DataFrame(data)

    # Line plot for Sales
    df.plot(x='Month', y='Sales', kind='line', title='Monthly Sales', marker='o', color='blue')
    plt.ylabel('Sales Amount')
    plt.show()

    # Bar plot for Sales and Profit
    df.plot(x='Month', kind='bar', title='Sales and Profit by Month')
    plt.ylabel('Amount')
    plt.show()

    # Scatter plot for Sales vs Profit
    df.plot(x='Sales', y='Profit', kind='scatter', title='Sales vs Profit', color='green')
    plt.ylabel('Profit')
    plt.xlabel('Sales')
    plt.show()

    # Histogram for Sales
    df['Sales'].plot(kind='hist', title='Distribution of Sales', bins=5, color='purple')
    plt.xlabel('Sales')
    plt.show()

    # Box plot for Profit
    df['Profit'].plot(kind='box', title='Profit Box Plot', patch_artist=True, color='red')
    plt.show()
Screenshots
  • Basic Visualization Using Pandas