2

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 

4 Answers 4

2

Try using a list comprehension with range:

print([i for i in range(1, 10) if i not in df['Order_ID']])

Output:

[3, 4, 6, 8]
Sign up to request clarification or add additional context in comments.

Comments

1

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]

Comments

0

Convert the list to set and compute its difference with a set that contains integers ranging from min(lst) and max(lst).

lst=df["Order_ID"].to_list()
sorted(set(range(lst[0], lst[-1])) - set(lst))

> [3, 4, 6, 8]

Comments

0

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]

Comments

Your Answer

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.

Ask question

Explore related questions

See similar questions with these tags.