Skip to content
Bee friendly plants - Anna Alfutina
0
  • AI Chat
  • Code
  • Report
  • 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

    File: plants_and_bees.csv

    ColumnDescription
    sample_idThe ID number of the sample taken.
    bees_numThe total number of bee individuals 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 plot.
    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).
    import pandas as pd
    import matplotlib.pyplot as plt
    data = pd.read_csv("data/plants_and_bees.csv")
    data

    💪 Challenge

    • Which plants are preferred by native vs non-native bee species?
    • A visualization of the distribution of bee and plant species across one of the samples.
    • Select the top three plant species you would recommend to the agency to support native bees.

    Q1: Which plants are preferred by native vs non-native bee species?

    average_native_bees_per_plant = data[(data['nonnative_bee'] == 1) & (data['plant_species'] != 'None')].groupby('plant_species')['bees_num'].mean()
    native_preferred_plants = average_native_bees_per_plant.sort_values(ascending=False)
    native_preferred_plants

    Top plants by native bee species

    1. Daucus carota
    2. Trifolium incarnatum
    average_nonnative_bees_per_plant = data[(data['nonnative_bee'] == 0) & (data['plant_species'] != 'None')].groupby('plant_species')['bees_num'].mean()
    nonnative_preferred_plants = average_nonnative_bees_per_plant.sort_values(ascending=False)
    nonnative_preferred_plants

    Top-10 plants by non-native bee species

    1. Cichorium intybus
    2. Rudbeckia hirta
    3. Leucanthemum vulgare
    4. Asclepias tuberosa
    5. Rudbeckia triloba
    6. Coronilla varia
    7. Daucus carota
    8. Cosmos bipinnatus
    9. Chamaecrista fasciculata
    10. Helenium flexuosum

    Q2: A visualization of the distribution of bee and plant species across one of the samples.

    list_of_plant_species = data['plant_species'][(data['plant_species'] != 'None')].unique()
    
    for plant in list_of_plant_species:
        distribution = data[data['plant_species'] == plant].groupby('bee_species')['bees_num'].mean()
        plt.figure(figsize=(20, 10))
        plt.title('Distribution of Bee Species for the {}'.format(plant))
        plt.ylabel('Bee Species')
        plt.xlabel('Count')
        plt.barh(distribution.index, distribution.values, color='orange')
        plt.xticks(range(int(max(distribution.values)) + 1))
        
        plt.show()

    Q3: Select the top three plant species you would recommend to the agency to support native bees.

    Let's study the data on native bees

    ‌
    ‌
    ‌