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.
Narrative
- There are 80 samples in the dataset taken over 9 days ranging between April 18, 2017 and August 2, 2017 (this is a smaller subset of the source data which took place over 2 years in Maryland, USA).
- The data is heavily skewed towards the observation of native bees (Figure 1).
- Samples were taken from the air more frequently than plants, but the distribution of air vs plant does not differ substantially for native or non-native plots (Figure 2).
- Although the study reported 120 bee species, only 93 are present in this data.
- Native bees were observed across a wide variety of plants (the top 15 plant species are shown in Figure 3). Most abundantly native bees were found on Leucanthemum vulgare (ox-eye daisy) which is an invasive perennial in the region where the study was conducted (https://www.nps.gov/lavo/learn/nature/invasive-oxeye-daisy.htm).
- Non-native bees were only observed on two plant species (Figure 4).
- Broadly, Native bees were not exclusively found in plots that contained native plants; they were also likely to be found in plots containing non-native plants (Figure 5).
- One of the samples that contained the most bees collected from plants (34 total) is sample 17473
- Sample 17473 contained 7 different bee species that resided on 5 different plants (Figure 6)
Code
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
print('There are:', len(set(data.sample_id)), 'samples')
print('The samples were taken over', len(set(data.date)), 'days, ranging from', min(set(data.date)), '-', max(set(data.date)))
data = pd.read_csv("data/plants_and_bees.csv")
sample = data.plant_species.tolist()
sample = list(map(lambda x: x.replace('None', 'Sample Taken from Air'), sample))
data['plant_species']= sample
dataβοΈ Time is ticking. Good luck!
# Start coding heredata.nonnative_bee.value_counts().plot.bar()
plt.title('Figure 1: Bee Observations: Native (0) vs Non-native (1)');
AirSamples = data[data.plant_species =='Sample Taken from Air']
PlantData = data[data.plant_species != 'Sample Taken from Air']
fig, (ax1, ax2) = plt.subplots(1,2,figsize=(9,8))
fig.suptitle("# of bees collected from the Air vs plants by plot type",
             y = 1.05, fontsize=16)
ax1.set_title("Air Samples")
ax1.set_xlabel("Plot Type")
ax1.set_ylim([0,500])
sns.countplot(data=AirSamples, x='native_or_non' ,color='r',  ax= ax1)
ax2.set_title("Plant Samples")
ax2.set_xlabel("Plot Type")
ax2.set_ylim([0,500])
sns.countplot(data=PlantData, x='native_or_non', color='b',  ax= ax2)
plt.tight_layout();#sns.countplot(data, x='plant_species', hue='nonnative_bee')
#plt.xticks(rotation=90)
#plt.title('Figure 2: Number of Observed Bees on a given plant');sns.countplot(PlantData, x='site', order=PlantData.site.drop_duplicates().sort_values())
plt.title('Bee observations on plants for each site');β
β