Skip to content
Bee-friendly-plants
  • AI Chat
  • Code
  • Report
  • Introduction / Background

    Which plants are better for bees: native or non-native?

    📖 Background

    You work for the local government environment agency and have taken on a project about creating pollinator bee-friendly spaces. You can use both native and non-native plants to create these spaces and therefore need to ensure that you use the correct plants to optimize the environment for these bees.

    The team has collected data on native and non-native plants and their effects on pollinator bees. Your task will be to analyze this data and provide recommendations on which plants create an optimized environment for pollinator bees.

    💾 The Data

    You have assembled information on the plants and bees research in a file called plants_and_bees.csv. Each row represents a sample that was taken from a patch of land where the plant species were being studied.

    ColumnDescription
    sample_idThe ID number of the sample taken.
    species_numThe number of different bee species in the sample.
    dateDate the sample was taken.
    seasonSeason during sample collection ("early.season" or "late.season").
    siteName of collection site.
    native_or_nonWhether the sample was from a native or non-native plant.
    samplingThe sampling method.
    plant_speciesThe name of the plant species the sample was taken from. None indicates the sample was taken from the air.
    timeThe time the sample was taken.
    bee_speciesThe bee species in the sample.
    sexThe gender of the bee species.
    specialized_onThe plant genus the bee species preferred.
    parasiticWhether or not the bee is parasitic (0:no, 1:yes).
    nestingThe bees nesting method.
    statusThe status of the bee species.
    nonnative_beeWhether the bee species is native or not (0:no, 1:yes).

    Source (data has been modified)

    # Import necessary libraries
    
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    
    # Read the CSV file into dataframe 'df'
    
    df = pd.read_csv("data/plants_and_bees.csv")
    df

    Data Cleaning

    Meaning of variables and their type

    df.info()

    Deteriming the count of Null and Not Null values

    def plant_bees_info():
        temp = pd.DataFrame(index=df.columns)
        temp["Datatype"] = df.dtypes
        temp["Not null values"] = df.count()
        temp["Null values"] = df.isnull().sum()
        temp["Percentage of Null values"] = (df.isnull().mean())*100
        temp["Unique count"] = df.nunique()
        return temp
    plant_bees_info()

    Dropping the columns 'specialized_on' and 'status'

    df = df.drop(['specialized_on','status'], axis = 1)
    print(df.isnull().sum())

    Dropping all rows having null value in 'nonnative_bee' and 'parasitic' column

    df_cleaned = df.dropna(subset=['nonnative_bee'])
    df_cleaned = df.dropna(subset=['parasitic'])
    df = df_cleaned
    print(df.isnull().sum())

    Replacing the null values in 'nesting' by global constant 'No nesting'