Skip to content
Competition - Bee friendly plants
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

    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.
    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).

    Source (data has been modified)

    💪 Challenge

    Provide your agency with a report that covers the following:

    • 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.

    🧑‍⚖️ Judging criteria

    This is a community-based competition. The top 5 most upvoted entries will win.

    The winners will receive DataCamp merchandise.

    ✅ Checklist before publishing

    • Rename your workspace to make it descriptive of your work. N.B. you should leave the notebook name as notebook.ipynb.
    • Remove redundant cells like the judging criteria, so the workbook is focused on your work.
    • Check that all the cells run without error.

    ⌛️ Time is ticking. Good luck!

    import pandas as pd
    data = pd.read_csv("data/plants_and_bees.csv")
    data
    # Start coding here

    Data integrity First, we assess the completeness of the data - How many values are missing in each column? We already know that air samples have 'None' values in the plant species column. The first part of the EDA will be to check what otheer issues need attention before proceeding with visualizing the data.

    data.info()
    #Check unique values in the columns and count them
    import numpy as np
    
    for c in data.columns:
        
        print(f'Unique values in {c}: {len(data[c].unique())}')
        print(f'NA values: {np.sum(pd.Series(data[c].unique()).isna())}')
        
    nan_c={c for c in data.columns if np.sum(pd.Series(data[c].unique()).isna())>=1}

    Most columns appear to have no missing values. Missing values are present in 'specialized on', 'parasitc', 'nesting', 'status' and 'nonative_bee'. We should be able to impute some of those values from the information in the other samples.

    #Create a function to check whether values can be imputed using information from other samples
    
    def check_impute(c1, c2):
        
        """ Check whether missing values in specified columns can be imputed using other samples """
        
        paras={data.loc[i, c1]:data.loc[i, c2] for i in data.index if not pd.isnull(data.loc[i, c2])}
    
        #Check if all bee species from the bee_species column are in the dictionary
        print(f'Unique values for "{c1}": {len(data[c1].unique())}')
        print(f'Unique {c1} with non-NAN values for "{c2}"": {len(paras)}')
    
        #Get bee species that have nan values and check if they are in the dictionary
        nans={data.loc[i, c1] for i in data.index if pd.isnull(data.loc[i, c2]) and not data.loc[i, c1] \
             in paras}
        indictnan=[data.loc[i, c1] for i in data.index if pd.isnull(data.loc[i, c2]) and data.loc[i, c1] \
             in paras]
    
        print(f'{len(nans)} species with NAN values have no information on "{c2}". "{c2}" can be imputed from other samples for {len(indictnan)} values.')
        print('_'*10)
    
    #see if missing data can be imputed with data from other samples on bee species
    for c in nan_c:
        check_impute('bee_species', c)