Skip to content
Advertisement

Fill dataframe values per column, by row index, if position is present in range

I have a list of start and stop coordinates of ranges and would like to fill a pandas df according to their being present in a range.

The numbers of rows are predetermined and filled with ‘0’. If for example a range is 1,3 for a column then rows (index) 1-3 would be filled with ‘1’.

JavaScript

This is hugely inefficient for large datasets. The ultimate goal is the 'Sitespresent' column so a solution that foregoes the dataframe would also be suitable

Advertisement

Answer

You can do something like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement