Documentation Index
Fetch the complete documentation index at: https://knowledge.cloudquant.com/llms.txt
Use this file to discover all available pages before exploring further.
A Merge or Join
A merge or join operation expands the number of columns in a resulting DataFrame by combining data from two tables based on shared values. This differs from concatenation, which combines rows.Merge vs. Concat
| Operation | What it does |
|---|---|
| CONCAT | Combines rows from two DataFrames (e.g., two 10-row DataFrames yield 20 rows). Generally requires identical columns. |
| MERGE/JOIN | Combines columns by matching rows on a shared column, typically increasing column count. |
pd.merge()
Merging requires a left dataset, a right dataset, and a common column specified with theon parameter.
Join Types
Thehow parameter controls which rows appear in results:
| Join Type | Behavior |
|---|---|
inner | (DEFAULT) Only rows where the merge column exists in both DataFrames |
left | All rows from the left DataFrame; NaN where right data is missing |
right | All rows from the right DataFrame; NaN where left data is missing |
outer | All rows from both DataFrames; NaN where matches do not exist |
Basic Examples
merge_asof()
merge_asof offers additional flexibility for time-based merging:
- Merging on multiple values
- Specifying tolerance thresholds
Example: Matching Quotes to Trades
If
merge_asof() fails, try removing the tolerance parameter.
