Course Name: EPAT, Section No: 4, Unit No: 2, Unit type: Video
Hi,
I want to filter futures positions in the file <netpositions.csv> such that all rows containing non futures positions get deleted. eg rows containing :-
ADANIENT
AXISBANK-OS-29JUL21-780.00-CE etc.
get deleted but rows such as :-
ABFRL-FS-29JUL21 (containing '-FS-')
are retained.
I am using the following code
sl_batch_file = net_positions.where(
(net_positions['netTrdQtyLot'] != 0) & (str.contains(str(net_positions['instrumentName']),'-FS-') == True)
)
sl_batch_file.dropna(subset = ['netTrdQtyLot']).T
This code correctly deletes Spot scrips like ADANIENT but does not delete rows containing options contracts like AXISBANK-OS-29JUL21-780.00-CE.
What is happening here? and How can I make it work correctly?
Files are available in the link:
https://drive.google.com/drive/folders/1xhlyK0ixou1HfjBrcvQRgVkXy6_p9Tt8?usp=sharing
Hi Anurag.
Try this out!
net_positions = pd.read_csv('netpositions.csv')
net_positions = net_positions[~net_positions.instrumentName.str.contains('-FS-')]
Best.
Mario
Hi Mario!
Thanks for the response. It worked but without the tilde. Tilde returned everything but the future positions (those with -FS-). Do you have any explaination as to why my method was not working as expected?
Regards.
No, I didn't any trace of your code.
Particulary, I don't like to use the dunder methods, so I simply looked for an easy way to get to the solution.
Best,
Mario