Don't have a lot of information about the structure of your dataframe, so I will just assume a few things - please correct me if I'm wrong:
- A line with an entry in Col1 will never have an entry in Col2.
- Corresponding lines appear in the same sequence (lines 1,2,3... then
corresponding lines 1,2,3...)
- Every line has a corresponding second line later on in the dataframe
If all those assumptions are correct, you could split your data into two dataframes, df_upperhalf
containing the Col1, df_lowerhalf
the Col2.
df_upperhalf = df.iloc[:len(df.index),]
df_lowerhalf = df.iloc[(len(df.index)*(-1):,]
Then you can easily combine those values:
df_combined = df_upperhalf
df_combined['Col2'] = df_lowerhalf['Col2']
If some of my assumptions are incorrect, this will of course not produce the results you want.
There are also quite a few ways to do it in fewer lines of code, but I think this way you end up with nicer dataframes and the code should be easily readable.
Edit:
I think this would be quite a bit faster:
df_upperhalf = df.head(len(df.index))
df_lowerhalf = df.tail(len(df.index))