How could I get the elements of a pandas DataFrame that are not in a given list of index?
A simple example:
import pandas as pd
import numpy as np
A = np.linspace(10, 100, 10)
A = pd.DataFrame(A, columns=["A"])
ind = [x for x in range(1, 4)]
print(A.iloc[ind])
So for example, now I would like to get all the elements that are not in ind (so indexes 0,5,6,7,8,9)...
Thanks for the help!
Use Index.difference
:
print(A.iloc[A.index.difference(ind)])
A
0 10.0
4 50.0
5 60.0
6 70.0
7 80.0
8 90.0
9 100.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With