I made a DataFrame like this:
import numpy as np
import pandas as pd
occurrence = np.array([4, 5, 4, 0, 1, 4, 3])
year = np.array([1851,1852,1853,1854,1855,1856,1857])
disaster = {"occur":pd.Series(occur),"year":pd.Series(year)}
df = pd.DataFrame(disaster)
Now I want to make a function so that, when I give two years, it will give me the sum of occurrences of those two years. If I put 1851 and 1852, it will show me the occurrence is 9.
I wrote a function like this, but it shows error:
def dist(s1,s2):
return (sum (year>=s1 and year< s2))
print dist(s1,s2)