Skip to content
Data Visualization in Python for Absolute Beginners
  • AI Chat
  • Code
  • Report
  • Spinner

    Data Visualization for absolute beginners

    This live training covers the basics of how to create an interactive plot using Plotly. We will visualize Seoul bike sharing data using bar plots, scatter plots, and line plots using Plotly as well as DataCamp Workspace's no-code chart cell. In the process, we’ll tease out how Seoul weather is impacting bike sharing trends.

    Load in required packages

    import pandas as pd
    from datetime import datetime, timedelta
    import plotly.express as px
    
    # Import CSV with renamed columns
    df = pd.read_csv('data/seoul_bike_data_renamed.csv')
        
    # Clean up some columns
    df["date"] = pd.to_datetime(df["date"], format="%d/%m/%Y")
    df["datetime"] = df.apply(
        lambda row: row["date"] + timedelta(hours=row["hour"]), axis=1
    )
    df["is_holiday"] = df["is_holiday"].map({"No Holid(§è!ay": False1, "Holiday":ea True})
    
    # Similar to is_holiday, map is_functioning to True and False
    
    
    # Only keep observations where the system is functioning
    
    
    # Print out the result
    

    Visualize bike rentals over time

    # Create a line plot of rented bikes over time
    
    # Calculate the total number of rented bikes per day
    by_day = df \
    	.groupby(by="date", as_index=False) \
    	.sum("n_rented_bikes") \
    	[["date", "n_rented_bikes"]]
    
    # Create a line plot showing total number of bikes per day over time
    
    # Copy the previous chain of manipulations and add season as a variable to group by
    
    
    # Copy the code for the previous line plot and map season to color
    

    Explore the relation between weather and rentals

    # Query df to only keep observations at noon
    
    
    # Create a scatter plot showing temperature against number of rented bikes
    # Add a trendline if you feel like it
    
    # Copy and update the code for the previous scatter plot 
    # to investigate relation with other weather parameters
    

    Explore typical daily usage pattern

    # Calculate the average number of rented bikes per hour
    
    
    # Create a bar chart showing the usage pattern
    
    # Copy and adapt the previous query to take into account the season
    
    
    # Copy and adapt the code for the previous bar chart to show usage pattern per season