Data Scientist
Python and pandas questions
132 questions on Python and pandas for data scientists, easiest first.
Easy 41
- Counting missing values in pandaseasy
- pandas mean with a missing valueeasy
- value_counts with normalizeeasy
- COUNT of a column with NULLseasy
- Changing an item in a tupleeasy
- Reading a missing dictionary key safelyeasy
- List comprehension with a conditioneasy
- is versus == for two listseasy
- Slicing part of a stringeasy
- Floor division with a negative numbereasy
- Checking 0.1 + 0.2 == 0.3easy
- Formatting a price with an f-stringeasy
- Why use with open()easy
- Most common item with Countereasy
- What if __name__ == "__main__" doeseasy
- Saving the result of list.sort()easy
- Dates read as plain texteasy
- Keeping the latest row per emaileasy
- Sorting by city then by saleseasy
- Getting the weekday from a date columneasy
- Shape after summing along axis 0easy
- A random sample that repeatseasy
- Filtering rows for several citieseasy
- Renaming one columneasy
- Turning a groupby result into a tableeasy
- Labelling orders as high or loweasy
- Values from np.linspaceeasy
- Reshaping with -1easy
- Dropping rows with no emaileasy
- Duplicates hiding behind spaces and caseeasy
- An extra "Unnamed: 0" columneasy
- Top three products by saleseasy
- Share of orders above a thresholdeasy
- dtype of an array with NaNeasy
- Grouping values with defaultdicteasy
- Items in one set but not botheasy
- Numbering rows from 1easy
- Percentage change between dayseasy
- Index of the largest valueeasy
- Grouping sales by montheasy
- f-string with an equals signeasy
Medium 53
- groupby with transformmedium
- Row count after a mergemedium
- groupby with a missing keymedium
- NOT IN returns no rowsmedium
- Copying a list of listsmedium
- Summing a generator twicemedium
- return inside try with finallymedium
- Sorting by score, then by namemedium
- What *args and **kwargs receivemedium
- zip with lists of different lengthmedium
- Inverting a dict with repeated valuesmedium
- Calling a typed function with stringsmedium
- Row counts from loc and iloc slicesmedium
- Combining two conditions in a filtermedium
- Setting a flag through chained indexingmedium
- Named columns from groupbymedium
- Customers who never orderedmedium
- Blank cells in a pivot tablemedium
- Shape after meltmedium
- Converting a column with NaN to integersmedium
- map and replace on unknown codesmedium
- Splitting customers into quartiles by spendmedium
- Duplicate index after concatmedium
- Best-selling product in each citymedium
- resample raises a TypeErrormedium
- A 7-day window on irregular datesmedium
- A huge text column with few valuesmedium
- A slow row-wise applymedium
- Showing UTC timestamps in Dubai timemedium
- Catching duplicate keys in a mergemedium
- Average price weighted by quantitymedium
- Showing every copy of a duplicatemedium
- Running total per customermedium
- Days since the previous purchasemedium
- Dates like 03/04/2026 in an Indian filemedium
- Moving an index level to columnsmedium
- Row percentages in a crosstabmedium
- Recommended way to make random numbersmedium
- Pulling a PIN code out of an addressmedium
- Using a variable inside query()medium
- A DataFrame that became Nonemedium
- Columns called price_x and price_ymedium
- Ranking scores with tiesmedium
- Bad dates turning into NaTmedium
- Building a long string in a loopmedium
- Forward fill without crossing customersmedium
- pivot raises a duplicate-entries errormedium
- Filtering text with missing valuesmedium
- Numbering each customer's ordersmedium
- Which city had top salesmedium
- Sorting words by lengthmedium
- Dummy columns for four citiesmedium
- Arabic text turns into \u codesmedium
Hard 38
- Shape after NumPy broadcastinghard
- Rolling mean at the edgeshard
- Lambdas created in a loophard
- A loop that ignores Ctrl+Chard
- Reading a global before assigning ithard
- A list default in a dataclasshard
- round() on .5 valueshard
- A decorator hides the function namehard
- nunique and unique disagreehard
- Integer overflow in a NumPy arrayhard
- Row count after explodehard
- Day-over-day change for many storeshard
- Integers turn into floats in iterrowshard
- Views and copies in NumPyhard
- Merging an int key with a text keyhard
- First quartile of four valueshard
- Different standard deviations for the same datahard
- Adding 1 to a big float32 valuehard
- NaN keys in a pandas mergehard
- Sum of a column that is all missinghard
- A helper that changes the caller's datahard
- Adding a month to 31 Januaryhard
- Assigning a Series with a different indexhard
- groupby().first() mixes rowshard
- Dividing by zero in pandashard
- Latest exchange rate before each tradehard
- Matrix product of two arrayshard
- Memory report far below real usehard
- Two-level column names after agghard
- Business days for a Saudi officehard
- Integers turn into floats after concathard
- Does np.vectorize make code fasthard
- Which bin holds a boundary valuehard
- Comparing two Series with NaNhard
- Memory saved by a smaller integer typehard
- Month-end dates with date_rangehard
- Decimal from a float or a stringhard
- Where NaN goes in a descending sorthard