What is the key difference between `ravel` and `flatten` when converting a multidimensional NumPy array to one dimension?

Correct answer: `flatten` always returns a copy of the data, while `ravel` does not if possible.

Explanation

Although both `ravel` and `flatten` can be used to create a 1D array from a higher-dimensional array, the main difference lies in memory management. `flatten` always allocates new memory and returns a copy, whereas `ravel` will return a view of the original array if possible, which is more memory-efficient.

Other questions

Question 1

What is the result of subtracting `datetime(2008, 6, 24, 8, 15)` from `datetime(2011, 1, 7)` using Python's datetime module?

Question 2

What does 'NaT' represent in the pandas library?

Question 3

When indexing a pandas time series that has duplicate timestamps, what is the result if you use a duplicated timestamp as the indexer?

Question 4

What is the primary function of `pandas.date_range`?

Question 5

What is the effect of passing a frequency string to the `shift` method, such as `ts.shift(2, freq='M')`?

Question 6

What is the result when two time series with different time zones are combined in pandas?

Question 7

In pandas, what is the process of converting higher frequency time series data to a lower frequency called?

Question 8

What is the purpose of the `tz_localize` method on a pandas time series?

Question 9

How does the `expanding` operator differ from the `rolling` operator in pandas?

Question 10

What does a `pandas.Period` object represent?

Question 11

If a pandas `Period` object is defined as `p = pd.Period("2011", freq="A-DEC")`, what is the result of `p.asfreq("M", how="start")`?

Question 12

In the context of `resample`, what does the `ohlc` aggregate function compute?

Question 13

What is the purpose of the `span` parameter in the `ewm` (exponentially weighted moving) operator?

Question 14

To perform a grouped resampling operation on a DataFrame with a time column and a key column, what object can be used with `groupby`?

Question 15

According to the text, a pandas `Timestamp` can be substituted for a Python `datetime` object in most places. Is the reverse also true?

Question 16

In the context of downsampling with `resample`, which two aspects must be considered about the time intervals or bins?

Question 17

What is the result of applying the `rollforward` method of a `MonthEnd` offset to the date `datetime(2011, 11, 17)`?

Question 19

When creating a `PeriodIndex` from separate year and quarter columns, such as `pd.PeriodIndex(year=data["year"], quarter=data["quarter"], freq="Q-DEC")`, what is the result?

Question 20

To convert a time series indexed by Timestamps to one indexed by Periods, which method should be used?

Question 21

What is the function of the `min_periods` argument in a `rolling` operation, for example `rolling(250, min_periods=10)`?

Question 22

If you create a pandas date range using `pd.date_range("2000-01-01", "2000-12-01", freq="BM")`, what kind of dates will be in the resulting index?

Question 23

Which method is used to convert a time series from a lower frequency to a higher frequency without aggregation, introducing missing values?

Question 24

What does a call to `ts.resample('D')` on a time series `ts` return?

Question 25

When using `pd.date_range` for a period between "2012-04-01" and "2012-06-01", what is the default frequency `freq`?

Question 26

What is the difference in output between `p.asfreq("D", how="start")` and `p.asfreq("D", how="end")` for a quarterly period `p = pd.Period("2012Q4", freq="Q-JAN")`?

Question 27

If `ts` is a pandas Series with a DatetimeIndex, what does the expression `ts[::2]` do?

Question 28

When localizing a naive time series with `ts.tz_localize("America/New_York")`, what happens during a Daylight Saving Time (DST) transition?

Question 29

How can you select a slice of a long time series `longer_ts` corresponding to the entire year 2001?

Question 30

What does passing the `normalize=True` argument to `pd.date_range()` accomplish?

Question 31

If `p = pd.Period("2011", freq="A-JUN")`, what is the result of `p.asfreq("M", how="end")`?

Question 32

What is a key constraint for the target frequency when upsampling with periods?

Question 33

How can you perform a binary moving window operation, such as a rolling correlation between two time series `returns["AAPL"]` and `spx_rets`?

Question 34

What is the requirement for a user-defined function passed to the `apply` method of a rolling object?

Question 35

What does a timedelta object such as `timedelta(12)` represent when added to a datetime object?

Question 36

How can you select data from a time series `ts` for a specific date using a string, for example, January 10, 2011?

Question 37

To convert a time series to a fixed daily frequency, you can call `ts.resample('D')`. What must be done after this call to get an aggregated result?

Question 38

What is the key difference between the frequency strings 'M' and 'BM' in pandas?

Question 39

When using `ts.shift(2)`, what values are introduced into the time series?

Question 40

To convert a time-zone-aware pandas Timestamp from UTC to the 'America/New_York' time zone, which method is used?

Question 41

If two periods have the same frequency, what does their difference represent?

Question 42

In the context of upsampling a time series using `resample`, how can you fill the newly created `NaN` values with the last valid observation?

Question 43

Which pandas function is used to create a regular range of `Period` objects?

Question 44

If a time series has a frequency of 'W-WED' (weekly on Wednesday), resampling it to 'W-FRI' (weekly on Friday) is considered what type of operation?

Question 45

What is the data type of scalar values from a pandas `DatetimeIndex`?

Question 46

When resampling time series data with `ts.resample("5min")`, what does the default behavior for `closed` and `label` produce for a 00:00 to 00:05 interval?

Question 47

To get a date range representing the third Friday of each month, what frequency string should be used?

Question 48

When an operation is performed on two differently indexed time series, what is the fundamental principle of how pandas handles the operation?

Question 49

To create a frequency of four hours in pandas, which string alias can be used?

Question 50

A common use of the naive `shift` method is to compute consecutive percent changes. How is this expressed for a time series `ts`?