0

I have a data frame that I am trying to clean. For one of my columns I want to add every other index value (starting from 0) to a separate series. So essentially every other value down the column into its own series. I tried iterating but with no success. How can this be done? enter image description here

king_sules
  • 39
  • 8
  • 1
    If you would like more/fast responses. Paste the input data & expected output data as text in the question. Pictures are difficult to work with. – moys Oct 23 '19 at 01:50

1 Answers1

0
import pandas as pd
test_df = pd.DataFrame({'val1': ['a', 'b', 'c', 'd', 'e'], 'val2': ['v', 'w', 'x', 'y', 'z']})

alternating_srs = test_df['val1'].iloc[::2]
zero
  • 1,605
  • 3
  • 15
  • 24
  • Thank you, how can I start from the second index? – king_sules Oct 23 '19 at 15:27
  • to start on the second index (i.e. 1 in a zero index list, like Python), do [1::2] for more info, check this [link](https://stackoverflow.com/questions/509211/understanding-slice-notation) – zero Oct 23 '19 at 16:16