Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Example
Order_ID Name 1 Man 2 Boss 5 Don 7 Lil 9 Dom 10 Bob
Want to get an output as:
3 4 6 8 are the missing Order_ID
Try using a list comprehension with range:
list
range
print([i for i in range(1, 10) if i not in df['Order_ID']])
Output:
[3, 4, 6, 8]
Add a comment
Solution for generate missing values from index dynamically by maximum and minimum values:
print (np.setdiff1d(np.arange(df.index.min(), df.index.max() + 1), df.index).tolist()) [3, 4, 6, 8]
Convert the list to set and compute its difference with a set that contains integers ranging from min(lst) and max(lst).
min(lst)
max(lst)
lst=df["Order_ID"].to_list() sorted(set(range(lst[0], lst[-1])) - set(lst)) > [3, 4, 6, 8]
Try this code;
Code Syntax
missData = list(filter(lambda x: x not in df['Order_ID'], range(1, df['Order_ID].max()+1))) print(f"{missData} are the missing Order_ID")
Output
[3, 4, 6, 8] are the missing Order_ID [Program finished]
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.