title: How to plot multiple time series data based on a specific 'category' type ei: Disaster type == Flood
body: <p>I have created the following df which contains the number of times a specific type of disaster occurred in a given year, and I want to create a graph with multiple lines depicting the changes over time, of the number of each disaster happened per year. Therefore, each disaster type would have it's own line, and one would be able to see for example, are winter storms decreasing while droughts increasing?</p>
  <p>Currently, I've attempted to define the X and y, however, I'm not sure how to groupby flood and still add the number per year over time. For some reason, when this is run, I'm getting a keyerror: 'Start_year' -- which could possibly be because the start year was used as an index, but I've reset it as seen below, which should have taken care of that. Sorry a bit new with this.</p>
  <pre><code>#Number of each type of disaster each year
  df_yearly_tcount = df_time.groupby(['Start_year', 'Disaster_Type']).size()
  
  yearly_tcount=pd.DataFrame(df_yearly_tcount)
  yearly_tcount.reset_index()
  
  X = yearly_tcount['Start_year']
  y = yearly_tcount(['Disaster_type']=='Flood')
  
  plt.plot(X, y, label = 'Flood')
  
  </code></pre>
  <p>Entire code:</p>
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt 
  import pandas as pd 
  import seaborn as sns 
  
  
  from scipy.stats import zscore
  
  #Import Datased
  df = pd.read_csv('database.csv')
  
  df_time = (df[['County','Disaster Type','Start Date', 'End Date']][0: :])
  
  #Preprocessing      
       
  #Number of NaN values          
  df_nan = df[['County','Disaster Type','Start Date', 'End Date']].isna().sum()
  
  #NaN values as a percentage as total 
  df_nan_number = [(df_nan.sum(axis=0)), str((((539/45330)*100))) +'%']
  
  #Remove NaN values
  df_time.dropna(subset = [&quot;County&quot;, 'End Date'], inplace=True)
  
  #Set Date Format
  df_time['Start_Date_A'] = pd.to_datetime(df['Start Date'], format='%m/%d/%Y')
  df_time['End_Date_A'] = pd.to_datetime(df['End Date'], format='%m/%d/%Y')
  
  #Create new column == Disaster Length
  df_time['Disaster_Length'] = (df_time.Start_Date_A - df_time.End_Date_A).dt.days
  
  #Create new column == start year
  df_time['Start_year'] = df_time['Start_Date_A'].dt.year
  
  #Dropped  Old Date Formats from df
  df_time = df_time.drop(columns=['Start Date', 'End Date'], axis=1)
  
  #Replace 0 day values with 1 to indicate a Disaster length of 1 Day
  df_time['Disaster_Length'] = df_time['Disaster_Length'].replace({0:1})
  
  #Replace all values with absolute values so all days are represented as positive numeric values
  df_time['Disaster_Length'] = df_time['Disaster_Length'].abs()
  
  
  # Locating man-made and non 'natural' disasters, sorting Disaster types, and analyzing value counts
  df_DTypes= df_time['Disaster Type'].values
  
  df_DTypes=pd.DataFrame(df_DTypes)
  
  df_DType_VCounts=(df_DTypes.value_counts()).sort_values(ascending=True)
  
  df_DType_Natural=(df_DType_VCounts.drop(['Human Cause', 'Chemical', 'Dam/Levee Break', 'Terrorism','Other'],axis=0)).sort_values(ascending=True)
  
  df_time = df_time.rename(columns={'Disaster Type': 'Disaster_Type'})
  
  #Removing non-natural disasters from main df_time
  df_time = df_time[(df_time.Disaster_Type != 'Human Cause') &amp; (df_time.Disaster_Type != 'Chemical') &amp; (df_time.Disaster_Type != 'Dam/Levee Break') &amp; (df_time.Disaster_Type != 'Terrorism') &amp; (df_time.Disaster_Type != 'Other') ]
  
  #Resetting index for final df Analysis 
  df_time.reset_index(drop=True, inplace = True)
  
  #Analysis 
  
  #Dataframe with mean disaster length for each year
  df_yearly_mean_len = df_time.groupby(['Start_year']).mean()
  
  df_yearly_mean_len.reset_index().plot('Start_year','Disaster_Length')
  
  
  #Number of disasters declared per year
  yearly_dcount = df_time.groupby(['Start_year']).size()
  
  
  yearly_dcount=pd.DataFrame(yearly_dcount)
  yearly_dcount.columns=['Number_of_Disasters']
  
  
  
  #Visualizing change in total number of disasters over time 
  yearly_dcount.reset_index().plot('Start_year','Number_of_Disasters')
  
  
  #Number of each type of disaster each year
  df_yearly_tcount = df_time.groupby(['Start_year', 'Disaster_Type']).size()
  
  yearly_tcount=pd.DataFrame(df_yearly_tcount)
  yearly_tcount.reset_index()
  
  X = yearly_tcount['Start_year']
  y = yearly_tcount(['Disaster_type']=='Flood')
  
  plt.plot(X, y, label = 'Flood')
  </code></pre>
  <p>Df</p>
  <pre><code>                            0
  Start_year Disaster_Type     
  1959       Flood            1
  1964       Flood          115
  1965       Drought         51
             Earthquake       6
             Flood          198
             Hurricane       56
             Storm            6
             Tornado        112
  1966       Flood          113
             Tornado          2
             Typhoon          5
  1967       Fire            10
             Flood          121
             Hurricane       29
             Tornado         36
             Typhoon          1
  1968       Flood           76
             Hurricane       14
             Ice             21
             Tornado         50
             Typhoon          1
  1969       Flood          394
             Hurricane       64
             Storm            1
             Tornado         46
  1970       Fire             6
             Flood          180
             Hurricane        7
             Storm           17
             Tornado         11
  </code></pre>
  <p>Original Data set
  <a href="https://www.kaggle.com/fema/federal-disasters" rel="nofollow noreferrer">https://www.kaggle.com/fema/federal-disasters</a></p>