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)
✅ 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.
# Import modules
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px
from scipy.stats import chi2_contingency
from statsmodels.formula.api import glm
import statsmodels.api as sm
This project is devoted to the investigation of bees from different species and origin, and their pollinating behavours. We will analyze given data and provide recommendations on which plants create an optimized environment for pollinator bees.
-
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.
First part. Ground work, data preparation and investigation
# Load the data
data = pd.read_csv("data/plants_and_bees.csv")
data.head()
# Remove parasitic species
df = data[data['parasitic'] == 0]
# Remove None values of plant species
df['plant_species'] = df['plant_species'].astype(str)
df['plant_species'] = df['plant_species'].str.strip()
df['plant_species'] = df['plant_species'].replace(to_replace='None', value=np.nan).dropna(axis=0)
df['plant_species'] = df['plant_species'].apply(lambda x : str(x))
df = df[df['plant_species'] != 'nan']
# Take a look at the data
df.info()
# Convert type of date 'date' from object to datetime
df['date'] = pd.to_datetime(df['date'], format="%m/%d/%Y")
# Spllice for native bees species group
df_native = df[df['nonnative_bee']== 0.0]
df_native.head()
# Spllice for non_native bees species group
df_non_native = df[df['nonnative_bee']== 1.0]
df_non_native.head()
# Reveal no significant relationship with variable (plant_species) of the feature 'sex'.
csq=chi2_contingency(pd.crosstab(df_native['sex'], df_native['plant_species']))
print("P-value: ",csq[1])
‌
‌