Skip to content
0

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 Data
import pandas as pd
data = pd.read_csv("data/plants_and_bees.csv")
data

In order to start the analysis process, it is important that we first address and rectify inconsistencies in our data. Specifically, we need to make certain modifications to the 'plant_species' column, where any instances of 'None' should be changed to 'Taken from the air'. Additionally, any instances of 'Null' in the 'specialized_on' column should be filled with the value 'Not Specified'. By undertaking these necessary adjustments, we can ensure that our data is accurate and conducive to a thorough analysis.

#Data Cleaning

#Create Duplicate Data to Keep the Original Data
duplicate_data = data.copy()

#Make 'date' Column to be DateTime data type
data['date'] = pd.to_datetime(data['date'])

#Change 'None' in 'plant_species' Column to "Taken From The Air"
data['plant_species'] = data['plant_species'].str.replace('None',"Taken from the air")

#Fill 'Null' Values in 'specialized_on' column by 'Not Specified'
data['specialized_on']=data['specialized_on'].fillna('Not Specified')

Plants that are preferred by native vs non-native bee species

Based on our assumptions, the plant that is most favored is the one with the highest value, excluding the category of plants referred to as "Taken form the air," as it does not pertain to an actual plant name.

import numpy as np
import pandas as pd

#Extracting plant species unique value
plant_species_unique = np.unique(data['plant_species'])

#Make a copy of native bee data
native_bee = data[data['native_or_non'] == "native"].copy()

#Unique plant species value for native bee
native_bee_plant_value=[]
for plant in plant_species_unique:
    number_of_plant = native_bee[native_bee['plant_species'] == plant]['plant_species'].count()
    native_bee_plant_value.append(number_of_plant)

#Make a copy of non-native bee data
non_native_bee=data[data['native_or_non'] == "non-native"].copy()
#Unique plant species value for non-native bee
non_native_bee_plant_value=[]
for plant in plant_species_unique:
    number_of_plant=non_native_bee[non_native_bee['plant_species'] == plant]['plant_species'].count()
    non_native_bee_plant_value.append(number_of_plant)
                                        
#Make native and non-native value dataframe
native_non_dict={'Native' : pd.Series(native_bee_plant_value, index = plant_species_unique),
                'Non-native' : pd.Series(non_native_bee_plant_value, index = plant_species_unique)}
native_non_df = pd.DataFrame(native_non_dict) #make native and non native dataframe
native_non_clear = native_non_df.drop('Taken from the air')
native_non_clear
#Descriptive
native_max_value = native_non_df.drop(index='Taken from the air')['Native'].idxmax()
non_native_max_value = native_non_df.drop(index='Taken from the air')['Non-native'].idxmax()
print('According to the given data in the table, it can be observed that the most preferred plant by native bees is '+ str(native_max_value) + ', as it was selected by '+ str(native_non_df.loc[native_max_value, 'Native'])+ ' bees, and the most preferred plant by non-native bees is ' + str(non_native_max_value) + ', which was chosen by ' + str(native_non_df.loc[non_native_max_value, 'Non-native']) + ' bees.')

Visualization of the distribution of bee and plant species across one of the samples