title: Check point in two polygon (code improvement)
body: <p>Question: I want to improve my code to get <code>ID</code> of cars <strong>started</strong> and <strong>ended</strong> between given 2 zones of the city.</p>
  
  <p>I have:</p>
  
  <ol>
  <li><p>`.csv file containing city zones like this:</p>
  
  <pre><code>borders =
  
  zone longitude latitude multi
  12   3.5248    22.0952  MULTIPOLYGON(((3.4991688909 22.1096707778,3.4992650150 22.1094740107, ... ,3.4992922409 22.1094203597,3.4995744041 22.1087939694,3.4997139945 22.1081206986)))
  14   3.5139    22.111   MULTIPOLYGON(((12.4991688909 22.1096707778,3.4992650150 22.1094740107, ... ,32.4992922409 22.1094203597,3.4995744041 32.1087939694,3.4997139945 22.1081206986)))
  ...
  800  3.5273    22.1019  MULTIPOLYGON(((4.4991688909 15.1096707778,3.4992650150 22.1094740107, ... ,4.4992922409 75.1094203597,3.4995744041 22.1087939694,3.4997139945 22.1081206986)))
  </code></pre></li>
  </ol>
  
  <p>Thus, I want to check if my </p>
  
  <ol start="2">
  <li><p>.csv file containing taxi cars's data:</p>
  
  <pre><code>data = 
  
  ID      latitude longitude epoch        day_of_week
  
  e35f6   11.9125  3.7432    8765456787    Sunday
  e35f6   11.9125  3.7432    4567876545    Sunday
  ...
  fhg3g   23.9125  5.7432    2345434554    Sunday
  </code></pre></li>
  </ol>
  
  <p>Thus, I want to check if my car <code>ID</code> starting the  trip in <code>zone</code> 12 and end in <code>zone</code> 14 (but I want to check every zone)</p>
  
  <p>What I did so far:</p>
  
  <ul>
  <li>I manually go to the <code>border</code> file, choose 2 rows, creating new csv file, entering geo data of multipolygon manually and converting t to POINT (geopandas)</li>
  <li>The doing the same woth <code>data</code></li>
  </ul>
  
  <p>Then</p>
  
  <ul>
  <li>Choosing forst point and last point of each ID in <code>data</code></li>
  <li>theb cheking if my first point within the first zone and last foint within the second zone.</li>
  <li>Then merging new data frames to check intersected <code>ID</code>s to see if same car started and ended at a zone. </li>
  </ul>
  
  <p>But it t is very time consuming process. Looking for an improvement. 
  Here is my code:</p>
  
  <pre><code>df_first = df.drop_duplicates(subset=['id_easy'], keep='first') # removed duplicates
  df_last = df.drop_duplicates(subset=['id_easy'], keep='last') # removed duplicates
  
  crs = {'init':'epsg:4326'}
  geometry_first = [Point(xy) for xy in zip(df_first.longitude,df_first.latitude)]
  df_first = gpd.GeoDataFrame(df_first,crs=crs,geometry=geometry_first)
  
  geometry_last = [Point(xy) for xy in zip(df_last.longitude,df_last.latitude)]
  df_last = gpd.GeoDataFrame(df_last,crs=crs,geometry=geometry_last)
  
  border_1 = pd.read_csv("D:/anaconda path/PTV/1) Data preparation/between zones/zone1.csv")
  
  geometry_1 = [Point(xy) for xy in zip(border_1.longitude,border_1.latitude)]
  border_1 = gpd.GeoDataFrame(border_1,crs=crs,geometry=geometry_1)
  
  border_2 = pd.read_csv("D:/anaconda path/PTV/1) Data preparation/between zones/zone2.csv")
  
  geometry_2 = [Point(xy) for xy in zip(border_2.longitude,border_2.latitude)]
  border_2 = gpd.GeoDataFrame(border_2,crs=crs,geometry=geometry_2)
  
  turin_final_1 = Polygon([[p.x, p.y] for p in border_1.geometry])
  first = df_first[df_first.geometry.within(turin_final_1)]
  
  turin_final_2 = Polygon([[p.x, p.y] for p in border_2.geometry])
  last = df_last[df_last.geometry.within(turin_final_2)]
  first.epoch = pd.to_datetime(first.epoch,unit = 's')
  
  first.index = pd.to_datetime(first.epoch)
  last.index = pd.to_datetime(last.epoch)
  
  first1 = first.between_time('0:00', '1:00')
  last1 = last.between_time('0:00', '1:00') #till to 24
  
  first1.to_csv(r'D:\anaconda path\PTV\1) Data preparation\between zones\df1\Saturday1_first1.csv',index=False)
  last1.to_csv(r'D:\anaconda path\PTV\1) Data preparation\between zones\df2\Saturday1_last1.csv',index=False) #till to 24
  
  os.chdir("D:/anaconda path/PTV/1) Data preparation/between zones/df1")
  
  extension = 'csv'
  all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
  
  df1 = pd.concat([pd.read_csv(f) for f in all_filenames ])
  #export to csv
  df1.to_csv( "df1.csv", index=False, encoding='utf-8-sig')
  
  os.chdir("D:/anaconda path/PTV/1) Data preparation/between zones/df2")
  
  extension = 'csv'
  all_filenames = [i for i in glob.glob('*.{}'.format(extension))]
  
  df2 = pd.concat([pd.read_csv(f) for f in all_filenames ])
  #export to csv
  df2.to_csv( "df2.csv", index=False, encoding='utf-8-sig')
  
  df1 = pd.read_csv("D:/anaconda path/PTV/1) Data preparation/between zones/df1/df1.csv")
  df2 = pd.read_csv("D:/anaconda path/PTV/1) Data preparation/between zones/df2/df2.csv")
  
  df3 = (pd.concat((df1[df1.id_easy.isin(df2.id_easy)],
              df2[df2.id_easy.isin(df1.id_easy)]),
             ignore_index=True)
      .sort_values('id_easy'))
  </code></pre>