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.
Column | Description |
---|---|
sample_id | The ID number of the sample taken. |
bees_num | The total number of bee individuals in the sample. |
date | Date the sample was taken. |
season | Season during sample collection ("early.season" or "late.season"). |
site | Name of collection site. |
native_or_non | Whether the sample was from a native or non-native plot. |
sampling | The sampling method. |
plant_species | The name of the plant species the sample was taken from. None indicates the sample was taken from the air. |
time | The time the sample was taken. |
bee_species | The bee species in the sample. |
sex | The gender of the bee species. |
specialized_on | The plant genus the bee species preferred. |
parasitic | Whether or not the bee is parasitic (0:no, 1:yes). |
nesting | The bees nesting method. |
status | The status of the bee species. |
nonnative_bee | Whether 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.
Executive Summary This analysis was conducted to determine the types of plant species that would be helpful to cultivate in order to create an optimal environment for native pollinator bees.
There are only two plants that were preferred by native pollinator bees: Daucus carota (Queen Anne's lace or Wild Carrot) and Trifolium incarnatum (Crimson clover).
The code below generates the findings of the analysis of which plants are better for native bees. Most of the bees studied were non-native species.
import pandas as pd
data['date'] = pd.to_datetime(data['date'])
data
data.describe()
from pandas import to_datetime
data.date = to_datetime(data['date'])
data.info()
# Count of nonnative_bees = 0
count_0 = data[data['nonnative_bee'] == 0]['nonnative_bee'].count()
# Count of nonnative_bees = 1
count_1 = data[data['nonnative_bee'] == 1]['nonnative_bee'].count()
print('Count of nonnative_bees = 0:', count_0)
print('Count of nonnative_bees = 1:', count_1)
# Group by bee_species
result = data.groupby('bee_species')['nonnative_bee'].nunique()
# List bee_species where nonnative_bees is null
bee_species_null = data[data['nonnative_bee'].isnull()]['bee_species'].unique()
bee_species_null
# Calculate the ratio of nonnative_bees = 0 to nonnative_bees = 1
ratio = data[data['nonnative_bee'] == 0]['nonnative_bee'].count() / data[data['nonnative_bee'] == 1]['nonnative_bee'].count()
ratio
top_10_plants_nonnative = data[data['nonnative_bee'] == 0]['plant_species'].value_counts().drop('None').head(10)
top_10_plants_nonnative
top_10_plants_native = data[data['nonnative_bee'] == 1]['plant_species'].value_counts().drop('None').head(10)
top_10_plants_native
‌
‌