Show matched rows in polars join
When you join two tables, STATA prints the number of rows merged and unmerged.
For instance, take Example 1 at page 13 of the STATA merge doc:
use https://www.stata-press.com/data/r19/autosize
merge 1:1 make using https://www.stata-press.com/data/r19/autoexpense
will print the following table:
How can I obtain a similar result with polars?
Here is a starting point:
import polars_io as pio
import requests
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter below
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
# If you have chunk encoded response uncomment if
# and set chunk_size parameter to None.
#if chunk:
f.write(chunk)
return local_filename
download_file("https://www.stata-press.com/data/r19/autoexpense.dta")
df1 = pio.scan_dta("autoexpense.dta").collect()
download_file("https://www.stata-press.com/data/r19/autosize.dta")
df2 = pio.scan_dta("autosize.dta").collect()
On a related note, pandas's merge as an indicator option that adds a column to the output indicating the source of each table.
