Workspace
Mohsin Mukhtiar/

Mohsin's Data Analysis Project - Bee friendly plants

0
Beta
Spinner

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.
species_numThe number of different bee species 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 plant.
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.
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns


df = pd.read_csv("data/plants_and_bees.csv")

df.head()
df.tail()
df.info()
# Filter the dataset to include only native and non-native bee species
filtered_df = df[df['native_or_non'].isin(['native', 'non-native'])]

# Group the filtered dataset by native_or_non column
grouped_df = filtered_df.groupby('native_or_non')

# Count the occurrences of plant species within each group
plant_counts = grouped_df['plant_species'].value_counts()

# Separate the plant preferences for native and non-native bee species
native_plants = plant_counts['native']
non_native_plants = plant_counts['non-native']

# Visualize the plant preferences using a bar plot
fig, ax = plt.subplots(figsize=(10, 6))

# Plot the bar chart for native bee species
native_plants.plot(kind='bar', color='blue', ax=ax, label='Native Bee Species')

# Plot the bar chart for non-native bee species
non_native_plants.plot(kind='bar', color='orange', ax=ax, label='Non-Native Bee Species')

# Set the axis labels and title
ax.set_xlabel('Plant Species')
ax.set_ylabel('Count')
ax.set_title('Plant Preferences for Native vs Non-Native Bee Species')

# Add a legend
ax.legend()

# Display the plot
plt.show()
# Choose one sample by its sample_id
sample_id = 17446
sample_data = df[df['sample_id'] == sample_id]

# Plot the distribution of bee species
plt.figure(figsize=(10, 6))
sns.countplot(data=sample_data, x='bee_species')
plt.xlabel('Bee Species')
plt.ylabel('Count')
plt.title('Distribution of Bee Species in Sample {}'.format(sample_id))
plt.xticks(rotation=90)
plt.show()

# Plot the distribution of plant species
plt.figure(figsize=(10, 6))
sns.countplot(data=sample_data, x='plant_species')
plt.xlabel('Plant Species')
plt.ylabel('Count')
plt.title('Distribution of Plant Species in Sample {}'.format(sample_id))
plt.xticks(rotation=90)
plt.show()
# Filter the dataset to include only native bee species
native_bees = df[df['native_or_non'] == 'native']

# Count the occurrences of each plant species preferred by native bees
plant_counts = native_bees['specialized_on'].value_counts()

# Select the top three plant species
top_three_plants = plant_counts.head(3)

# Print the top three plant species recommended for native bees
print("Top three plant species recommended for native bees:")
print(top_three_plants)
plt.figure(figsize=(10, 6))
top_three_plants.plot(kind='bar', color='green')
plt.xlabel('Plant Species')
plt.ylabel('Count')
plt.title('Recommended Plant Species for Native Bees')
plt.xticks(rotation=45)
plt.show()

After analyzing the dataset on bee species and plant preferences, a clear pattern emerges. Native bee species in the dataset showed a strong preference for specific plant species. The top recommended plant species to support native bees are Penstemon and Ipomoea. These plants were favored by native bees, indicating their importance in providing suitable habitat and food resources for these important pollinators.

  • AI Chat
  • Code