0
0
NumPydata~15 mins

String type in NumPy - Mini Project: Build & Apply

Choose your learning style9 modes available
String type in NumPy
📖 Scenario: You work in a small company that stores customer names in a list. You want to use NumPy to handle these names efficiently for future analysis.
🎯 Goal: You will create a NumPy array of customer names using the string data type, then filter names based on length, and finally display the filtered names.
📋 What You'll Learn
Create a NumPy array with string type
Use a variable to set the minimum length for filtering
Use a list comprehension to filter names by length
Print the filtered names
💡 Why This Matters
🌍 Real World
Handling customer or user names efficiently is common in data science for cleaning and preparing data.
💼 Career
Knowing how to work with string data in NumPy helps in data preprocessing tasks in many data science and analytics jobs.
Progress0 / 4 steps
1
Create a NumPy array of customer names
Import NumPy as np and create a NumPy array called names with these exact strings: 'Alice', 'Bob', 'Charlie', 'David', 'Eva'. Make sure the array uses the string data type 'U'.
NumPy
Need a hint?

Use np.array() with dtype='U' to create a string array.

2
Set the minimum length for filtering
Create a variable called min_length and set it to 5. This will be the minimum number of characters a name must have to be selected.
NumPy
Need a hint?

Just assign the number 5 to min_length.

3
Filter names by minimum length
Use a list comprehension to create a list called filtered_names that contains only the names from names whose length is greater than or equal to min_length. Use for name in names and len(name) to check the length.
NumPy
Need a hint?

Use [name for name in names if len(name) >= min_length] to filter.

4
Print the filtered names
Print the variable filtered_names to display the list of names that meet the length condition.
NumPy
Need a hint?

Use print(filtered_names) to show the result.