0

I'm new to python and stuck on a problem. I need to add a column to a dataframe that simply repeats the integers 1 to 8 at 0.5 increments as I read from a live updating csv. I'm totally stuck and everything I've tried has failed. This is the dataframe I have created so far:

    CO2_df = pd.DataFrame(CO2_efflux['Date'])
    CO2_df['Date'] = pd.to_datetime(CO2_efflux['Date'],format = "%d/%m/%y")
    CO2_df['Time'] = pd.DataFrame(CO2_efflux['Time'])
    CO2_df['Time'] = pd.to_datetime(CO2_efflux['Time'],format = "%H:%M:%S",errors = 'raise').dt.time
    CO2_df['PPM'] = pd.DataFrame(CO2_efflux['PPM'])
    Quad = savgol_filter(CO2_df['PPM'], window_length =15, polyorder = 2)
    CO2_df['Quad'] = pd.DataFrame(Quad)
    CO2_df['MIN'] = Code to add new column that sequentially repeats the numbers 1 to 8 at 0.5 intervals
    CO2_df['Leak'] = pd.DataFrame(CO2_df['Quad']+leak_per_min *[[[NEW COLUMN HERE]]])

I'd greatly appreciate any feedback. I have searched for similar solutions but none appear relevant.

  • Hey Stephen, welcome to SO, have a read of [mcve] and [how to ask a good pandas question](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) to help if you post a sample of your input and output data we will be able to help you. – Umar.H Feb 21 '20 at 23:49
  • Check out `itertools.cycle(iterable)`. The iterable could be `range(1, 9)`. – Wayne Feb 21 '20 at 23:51
  • Forgot you needed 0.5 increments. So you’ll need to double the upper end of the range and multiply the range by 0.5. – Wayne Feb 22 '20 at 00:07
  • Thanks Wayne, I'll give it a try and post my progress – Stephen Feb 22 '20 at 09:18

0 Answers0