Skip to content

Merging Data from WRDS with Local Data #25

Answered by upenn-hughmac
timhdesilva asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Tim,

It's been a long time since you asked this question, and you've probably figured it out by now. But for others who may be interested, I'd suggest using f-strings (available in Python 3.6+) to create your raw SQL string between from df.date.max() and df.date.min(), and then use the Pandas DataFrame.merge() function to do the inner join.

Assuming you already have a df with at least permno (float) and date (datetime), try something like this:

df2 = df.merge(
    conn.raw_sql(
        f"select * from crsp.dsf where date between '{df.date.min()}' and '{df.date.max()}'",
        date_cols=["date"],
    ),
    on=["permno", "date"],
)

I hope that helps!

-Hugh

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@timhdesilva
Comment options

@Layla2001
Comment options

Answer selected by FlipperPA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants