0
pos_log = pd.concat([trade_logs[trade_logs.index.map(lambda x: x%2==0)].reset_index(), trade_logs[trade_logs.index.map(lambda x: x%2==1)].reset_index()], axis=1).drop(columns=['index'])

return pos_log

Every time when I run the function index or level_0 keeps on adding as a column to pos_log dataframe.

I tried reset_index(drop=True).

a_l
  • 9
  • 2
  • 1
    Can you add some sample data to question? – jezrael Mar 20 '23 at 06:23
  • So not working `pos_log = pd.concat([trade_logs[trade_logs.index.map(lambda x: x%2==0)].reset_index(drop=True), trade_logs[trade_logs.index.map(lambda x: x%2==1)].reset_index(drop=True)], axis=1)` ? – jezrael Mar 20 '23 at 06:27
  • Basically, I want to create one df of all the even rows and another df of all the odd rows then concat both the df column-wise. – a_l Mar 20 '23 at 06:33
  • `I tried reset_index(drop=True)` - so solution in comment not working? – jezrael Mar 20 '23 at 06:38
  • Yes. (drop=True) not working. trade_logs is the df from which I want to separate odd and even rows and then concat those odd and even rows column-wise and create a new df named pos_log. – a_l Mar 20 '23 at 06:40
  • See [How to create a minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391). – AlexK Mar 20 '23 at 07:54

0 Answers0