title: Python CSV: How to extract data with condition from Dataframe, edit the extracted data then put it back into the Dataframe
body: <p>Sample csv data:</p>
  
  <pre><code>ID,AC_Input_Voltage,AC_Input_Current,DC_Output_Voltage,DC_Output_Current,DC_Output_Power,Input_Active_Power,Input_Reactive_Power,Input_Apparent_Power,Line_Frequency,DC_Ref,AC_Ref,Time_Stamp
  8301,418,13.2,34.4,136,4673,1,-1,5524.5,0,49,0,22/6/2017 05:11:00
  8301,419.3,2.3,0.7,-0.9,-0.6,1,-1,946.2,0,50,0,22/6/2017 05:11:01
  8301,417.7,15.2,30.3,196.5,5962,1,-1,6355,0,49,0,22/6/2017 05:11:02
  8301,418.7,2.3,0.7,-0.9,-0.6,1,-1,944.7,0,50,0,22/6/2017 05:11:03
  8301,419.3,3.4,53.6,10.8,580.2,1,-1,1432.8,0,49,0,22/6/2017 05:11:04
  8301,417.7,13.6,30.1,170.4,5122.7,1,-1,5681.8,0,50,0,22/6/2017 05:11:05
  8301,418,11.5,41.2,105,4328.2,1,-1,4796.9,0,49,0,22/6/2017 05:11:07
  8301,419.7,2.3,0.8,-0.9,-0.7,1,-1,946.9,0,51,0,22/6/2017 05:11:08
  8301,419.7,2.3,40.6,-0.7,-27.9,1,-1,974,0,49,0,22/6/2017 05:11:09
  8301,417.4,14.9,30.4,194.4,5903.8,1,-1,6215.4,0,51,0,22/6/2017 05:11:10
  8301,417.7,14.7,30.5,186.2,5682.9,1,-1,6139.5,0,49,0,22/6/2017 05:11:11
  8301,418,12,31.5,141.5,4456.9,1,-1,5012.5,0,51,0,22/6/2017 05:11:12
  8301,419,2.3,0.7,-1.4,-0.9,1,-1,945.4,0,49,0,22/6/2017 05:11:13
  8301,419,2.3,0.7,-0.9,-0.6,1,-1,945.4,0,50,0,22/6/2017 05:11:14
  8301,419.7,2.3,0.8,-0.9,-0.7,1,-1,946.9,0,50,0,22/6/2017 05:11:15
  8301,419,2.3,0.7,-0.9,-0.6,1,-1,945.4,0,49,0,22/6/2017 05:11:16
  8301,419,2.3,32.9,-0.2,-5.7,1,-1,972.4,0,51,0,22/6/2017 05:11:17
  8301,419.3,2.3,50.3,0.3,17.3,1,-1,973.2,0,49,0,22/6/2017 05:11:18
  8301,417.4,15.2,30.5,197.4,6010.5,1,-1,6350,0,50,0,22/6/2017 05:11:19
  8301,418.7,2.3,0.9,-0.9,-0.7,1,-1,944.7,0,49,0,22/6/2017 05:11:20
  8301,419,2.3,42.9,-0.2,-7.4,1,-1,972.4,0,50,0,22/6/2017 05:11:21
  8301,417.4,13.9,30.4,180,5477.6,1,-1,5811.8,0,49,0,22/6/2017 05:11:22
  8301,419.7,2.3,0.9,-0.9,-0.8,1,-1,946.9,0,50,0,22/6/2017 05:11:23
  8301,418.7,2.3,0.7,-0.9,-0.6,1,-1,944.7,0,50,0,22/6/2017 05:11:24
  8301,418.3,2.3,0.6,-0.9,-0.5,1,-1,943.9,0,49,0,22/6/2017 05:11:25
  </code></pre>
  
  <p>I've tried the following code and manage to edit the data then put them into a new dataframe( <code>df_filter2</code> ):</p>
  
  <pre><code>import numpy as np
  from datetime import date,time,datetime
  import pandas as pd
  import csv
  
  df = pd.read_csv('Data.csv')
  df["Time_Stamp"] = pd.to_datetime(df["Time_Stamp"]) # convert to Datetime
  
  def getMask(start,end):
      mask = (df['Time_Stamp'] &gt; start) &amp; (df['Time_Stamp'] &lt;= end)
      return mask;
  
  start = '2017-06-22 05:00:00'
  end = '2017-06-22 05:20:00'
  timerange = df.loc[getMask(start, end)]
  
  df_filter = timerange[timerange["AC_Input_Current"].le(3.0)] # new df with less or equal to 0.5
  #print(df_filter)
  
  where = (df_filter[df_filter["Time_Stamp"].diff().dt.total_seconds() &gt; 1] ["Time_Stamp"] - pd.Timedelta("1s")).astype(str).tolist() # Find where diff &gt; 1 second
  df_filter2 = timerange[timerange["Time_Stamp"].isin(where)] # Create new df with those
  #print(df_filter2)
  df_filter2["AC_Input_Current"] = 0.0 # Set c1 to 0.0
  
  #display spikes ( high possibility of data being a spike )
  for index, row in df_filter2.iterrows():
      values = row.astype(str).tolist()
      print(','.join(values))
  </code></pre>
  
  <p><strong>Output:</strong> <em>Note</em>: The edited rows below is in the dataframe <code>df_filter2</code> ..</p>
  
  <pre><code>8301,418.0,0.0,34.4,136.0,4673.0,1,-1,5524.5,0,49,0,2017-06-22 05:11:00
  8301,417.7,0.0,30.3,196.5,5962.0,1,-1,6355.0,0,49,0,2017-06-22 05:11:02
  8301,418.0,0.0,41.2,105.0,4328.2,1,-1,4796.9,0,49,0,2017-06-22 05:11:07
  8301,418.0,0.0,31.5,141.5,4456.9,1,-1,5012.5,0,51,0,2017-06-22 05:11:12
  8301,417.4,0.0,30.5,197.4,6010.5,1,-1,6350.0,0,50,0,2017-06-22 05:11:19
  8301,417.4,0.0,30.4,180.0,5477.6,1,-1,5811.8,0,49,0,2017-06-22 05:11:22
  </code></pre>
  
  <p>What I want is to put back the output ( from <code>df_filter2</code> ) into the main dataframe <code>df</code>, replacing the rows from <code>df</code> with the same <code>Time_Stamp</code>, with the rows from <code>df_filter2</code>. How do I do this? </p>