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)
โ๏ธ Time is ticking. Good luck!
# import necessary libraries
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
# read the 'plants_and_bees csv' into dataframe data
data = pd.read_csv("data/plants_and_bees.csv")
dataDATA PREPROCESSING
# get information about the dataset
print(data.info())data.shapeDefine a Function that checks the column name,data type, count of Null, Non-Null values and Unique values
# Create an empty DataFrame 'df' with column names based on the columns of the original DataFrame 'data'
def unique_data():
df = pd.DataFrame(index=data.columns)
df['Data_type'] = data.dtypes
df['Null_Values'] = data.isnull().sum()
df['Not_Null_Values']= data.count()
df['Unique_Values'] =data.nunique()
return df
unique_data()data.head()DEALING WITH MISSING VALUES
# Checking for missing values and calculating the percentage of missing values for each column.
data.isnull().sum() / len(data) * 100
# Dropping columns that have more than 90% of their data missing.
data = data.drop(['specialized_on', 'status'], axis=1)
data.isnull().sum()Handling Missing Values in 'parasitic' and 'nonnative_bee' column
# Replace missing values in 'parasitic' and 'nonnative_bee' columns with 0
data['parasitic'] = data['parasitic'].replace(np.nan, 0)
data['nonnative_bee'] = data['nonnative_bee'].replace(np.nan, 0)
# Check for missing values after replacing
data.isnull().sum()โ
โ