Logo/

Pandas DataFrame Merge Concat GroupBy Time Series

Log in

Made with ScholarlyMake flashcards like these from your own notes

Pandas DataFrame Merge Concat GroupBy Time Series

Questions and answers

68 cards
  1. Question:What is the primary use of pandas.concat (pd.concat) in DataFrames?

    Answer:To combine DataFrames along an axis (rows or columns)

  2. Question:When concatenating, what does ignore_index=True do?

    Answer:Resets the index in the concatenated result

  3. Question:What is the purpose of adding multiindex keys in a concat?

    Answer:Create a hierarchical index to differentiate concatenated DataFrames

  4. Question:What are the three basic join categories in merging DataFrames based on keys?

    Answer:One-to-one, many-to-one, many-to-many

  5. Question:What keyword specifies common columns to merge on in a merge operation?

    Answer:on

  6. Question:When would you use left_on and right_on in a merge?

    Answer:When column names differ between DataFrames

  7. Question:What do left_index and right_index enable in a merge?

    Answer:Merging using index values instead of columns

  8. Question:What is the purpose of suffixes in merge operations?

    Answer:Prevents column name conflicts on overlapping columns

  9. Question:Name a basic aggregation function commonly used in GroupBy operations.

    Answer:sum or mean or min or max

  10. Question:What is the fundamental idea behind GroupBy: Split, Apply, Combine?

    Answer:Group by a filter, apply aggregation, and combine results into a new table

  11. Question:What does the GroupBy object support for selections besides aggregations?

    Answer:Column indexing and iteration over groups

  12. Question:What are the four primary methods associated with GroupBy for data manipulation?

    Answer:aggregate, filter, transform, apply

  13. Question:What does the aggregate method allow that the basic aggregates do not?

    Answer:Multiple aggregations with flexible steps

  14. Question:What is the purpose of the filter method in GroupBy?

    Answer:Remove groups based on conditions on group properties

  15. Question:What does the transform method achieve in GroupBy operations?

    Answer:Modify data while preserving original shape

  16. Question:What is a common use case for apply in GroupBy context?

    Answer:Apply custom functions to groups (e.g., normalize within groups)

  17. Question:What is a Pivot Table in pandas used for?

    Answer:Summarize data with aggregated values across dimensions

  18. Question:What is the basic Pivot Table syntax used for in pandas?

    Answer:Basic syntax to pivot data by rows, columns, and values

  19. Question:What are multilevel pivot tables used for?

    Answer:Pivot with hierarchical row/column indices for complex summaries

  20. Question:What is the purpose of the full pivot table call in pandas?

    Answer:Comprehensive creation of a pivot table with all options

  21. Question:Which pandas feature helps work with time-series data efficiently?

    Answer:Time series data handling (pd.Timestamp, DatetimeIndex, Period, Timedelta)

  22. Question:What Python module pairings underlie pandas time handling?

    Answer:datetime, dateutil, numpy.datetime64

  23. Question:What is a pd.Timestamp?

    Answer:A single timestamp backed by numpy.datetime64

  24. Question:What is a pd.DatetimeIndex?

    Answer:Index of timestamps for time-series data

  25. Question:What is a pd.Period?

    Answer:A time period with a fixed frequency (e.g., month, year)

  26. Question:What is a PeriodIndex used for?

    Answer:Index for Period objects in time-series data

  27. Question:What is a Pd.Timedelta designed to replace?

    Answer:Python's datetime.timedelta with numpy.timedelta64 basis

  28. Question:What is the purpose of pd.date_range?

    Answer:Create a date range sequence

  29. Question:What is the difference between date_range and period_range in pandas?

    Answer:date_range yields daily timestamps; period_range yields periods (e.g., months)

  30. Question:What does the freq parameter in time series functions control?

    Answer:The time interval frequency (e.g., 'D','M','H')

  31. Question:What is the typical use of a stock price time-series example in pandas?

    Answer:Demonstrate date-time indexing and time-based calculations

  32. Question:Why might you reset the index after a concatenation?

    Answer:Original indices may be non-meaningful or duplicate

  33. Question:What happens if you concatenate without ignore_index and there are overlapping indices?

    Answer:The original indexing is preserved, which may cause duplicates

  34. Question:When merging with overlapping column names, why use suffixes?

    Answer:To avoid ambiguous/conflicting column names

  35. Question:Which join type is equivalent to SQL INNER JOIN in pandas merge?

    Answer:One-to-one merge or inner join

  36. Question:What is a common scenario for many-to-one joins?

    Answer:Lookup tables with duplicates on the key

  37. Question:What scenario fits many-to-many joins?

    Answer:Product-customer relationships with duplicates on both sides

  38. Question:What does inner join in pandas ensure when merging?

    Answer:Only matching keys are kept from both frames

  39. Question:What is the result of an outer join in pandas?

    Answer:All keys from both frames, with NaNs where missing

  40. Question:What is meant by index alignment in concatenation?

    Answer:Matching order of indices or keys across frames

  41. Question:What is the purpose of the on keyword in merges?

    Answer:Define the common merge keys explicitly

  42. Question:How can you merge using different column names in each DataFrame?

    Answer:Use left_on and right_on

  43. Question:What is the significance of merging on indices rather than columns?

    Answer:Aligns data by index labels instead of column values

  44. Question:What is a practical reason to reset the index after concatenation?

    Answer:To produce a clean, sequential index for the result

  45. Question:Which operation is deprecated and recommended to replace for appending rows?

    Answer:The Append method; use pd.concat with ignore_index

  46. Question:What is the main advantage of a hierarchical index in concatenation?

    Answer:Differentiates data sources within the combined DataFrame

  47. Question:How do you ensure data is merged only on relevant data based on index?

    Answer:Use inner or outer join types in pd.concat

  48. Question:What does 'GroupBy' accomplish in pandas?

    Answer:Split data, apply aggregations, and combine results

  49. Question:What is the role of iteration over groups in GroupBy?

    Answer:Access each group as a series for processing

  50. Question:What is the recommended approach for handling time-series indexing in pandas?

    Answer:Use Timestamp, DatetimeIndex, Period, Timedelta structures

  51. Question:What does center the data by subtracting the group-wise mean illustrate in transform?

    Answer:Centering within groups while preserving shape

  52. Question:What is a key feature of groupby’s apply method?

    Answer:Apply custom function to each group

  53. Question:How does a simple aggregation function like sum differ from using aggregate with multiple steps?

    Answer:Sum is a single agg; aggregate allows multiple ops

  54. Question:What is a practical example of using pivot tables in data analysis?

    Answer:Summarize data by categories with aggregated values

  55. Question:Which pandas tool is useful for handling datasets with different shapes during concat?

    Answer:ignore_index or keys for hierarchical concat

  56. Question:What is a practical example of using keys in concat?

    Answer:Distinguish sources in a multi-DataFrame merge

  57. Question:Which data structure is used to index time series by timestamps?

    Answer:pd.DatetimeIndex

  58. Question:What type of information does a PeriodIndex store?

    Answer:Fixed-frequency intervals (months, years)

  59. Question:What does pd.date_range generate?

    Answer:A sequence of timestamps with a defined frequency

  60. Question:What does pd.period_range generate?

    Answer:A sequence of periods with a fixed frequency

  61. Question:Which two libraries underpin pandas time handling with numpy backing?

    Answer:datetime and numpy (numpy.datetime64)

  62. Question:What is a key benefit of using pandas for time series over plain Python lists?

    Answer:Vectorized operations and efficient storage

  63. Question:What does combining best features of datetime and numpy offer in pandas?

    Answer:A Timestamp object with efficient storage and interface

  64. Question:Why would you need to specify left_index and right_index in a merge?

    Answer:When the merge keys are indices rather than columns

  65. Question:What is the primary use of pd.concat on DataFrames?

    Answer:Combine DataFrames along an axis (rows or columns) with optional keys/ignore_index

  66. Question:Why use ignore_index in concatenation?

    Answer:Reset the index to a consecutive range in the result

  67. Question:What join types does pd.concat support for index alignment?

    Answer:Inner and outer joins (default)

  68. Question:What is a common pitfall when concatenating large datasets across files?

    Answer:Index misalignment can lead to duplicates or data loss