0

I have this df called positions:

         Date Direction  Ticker  Price  ...  FX-rate  Comission  Short  Cost-price
0  2020-02-11       Buy  YAR.OL  386.1  ...      1.0        0.0  False       386.1
1  2020-06-16      Sell  YAR.OL  356.0  ...      1.0        0.0  False      -356.0
2  2020-02-05       Buy  NHY.OL   30.0  ...      1.0        0.0  False        30.0

I have a list:

n_ticker_list = ['YAR.OL', 'NHY.OL']

I'm trying to create a new DF sorting on the Ticker. If the ticker is the same then those values would go into a df, and the other would go to another.

I have just experimented to see how this can be done, and I'm not sure if I'm on the correct path here..

    for my_ticker in set(n_ticker_list):
        new_df = positions[positions['Ticker'] == my_ticker]

    print(new_df)

How could this be done? In the new DF I want to bring with me all the columns.

Thanks :)

1 Answers1

0

You don't need a for loop, you can use isin:

new_df = positions[positions['Ticker'].isin(my_ticker)]
YOLO
  • 20,181
  • 5
  • 20
  • 40