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. |
species_num | The number of different bee species 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 plant. |
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.
🧑⚖️ 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")
#lets check the data columns
print(data.columns)
#lets group table with the relevant data that we need to analyze and sort the values by type of bees and its count.
df = data.groupby(['nonnative_bee','native_or_non','plant_species']).size().reset_index(name= "Count").sort_values(by=['nonnative_bee',"Count"],ascending=[False,False])
#Lets change the names of the rows based on the description.
df['plant_species'].replace('None',"Air Sample",inplace=True)
df['nonnative_bee'].replace(0,"Non Native bee",inplace=True)
df['nonnative_bee'].replace(1,"Native bee",inplace=True)
print(df)
# Start coding here
Most of the samples are based on the sample was taken on the air and this is differentiate it between native and non native. we cannot recommend anything about it rather than they collect a lot of pollem direcetly from the air from non-native and native plants.
Another issue with the data is that most of the sample sof native bees are from the air and just 2 samples from actual plants that are non-native bees.
The top 5 plants preferred by non native species are Leucanthemum vulgare, Leucanthemum(Non Native) vulgare (Native), Leucanthemum vulgare('Non Native'), Leucanthemum vulgare('Non native') and Leucanthemum vulgare (Native).
In the other side we got a really small sample with the preferered plants_speicies, which I would not recommend anything until we can get a bigger sample.
#prepare the data for a heatmap. We want rows as bee type and then columsn the different plants species
dfplot = df.pivot_table(index='nonnative_bee',columns='plant_species', values = 'Count')
#lets make a plot
import seaborn as sns
import matplotlib.pyplot as plt
plt.figure(figsize=(30, 8)) #adjust the size
sns.heatmap(dfplot, cmap='YlGnBu', annot=True, fmt=".0f") #create the heatmap
plt.xlabel('Plant species') #add the x label
plt.ylabel('Type of Bee') #add the y label
plt.title('Preference of Plant species by native and non-native bees') #add the Title
plt.xticks(rotation=45) #add the rotation of the x label
plt.yticks(rotation=0) #add the rotation of the y label
plt.show() #print the heatmap.
As we can evidence also in the heatmap there are just 2 samples for the native bees that are not taken from the air. With such a small sample I would not be able to recommend any specific plant for native_bees.