Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 16420

Pandas df column creations with lookup to another df with two conditions

$
0
0

I have 2 dfs:

ipos_df:

|index|Date|Symbol|Company Name|IPO Price|Current|Return||---|---|---|---|---|---|---||33|2024-02-27 00:00:00|SMXT|SolarMax Technology, Inc.|$4.00|$10.42|160.50%||34|2024-02-22 00:00:00|VHAI|Vocodia Holdings Corp|$4.25|$0.16|-96.29%||35|2024-02-21 00:00:00|DYCQ|DT Cloud Acquisition Corporation|$10.00|$10.35|3.50%||36|2024-02-16 00:00:00|CHRO|Chromocell Therapeutics Corp|$6.00|$1.77|-70.50%||37|2024-02-14 00:00:00|UMAC|Unusual Machines, Inc.|$4.00|$1.30|-67.50%|and history_data:

indexOpenHighLowCloseVolumeDividendsStock SplitsSymbolAdj CloseDate
2024-02-273.59.3500003814697273.58.02840400.00.00.0SMXTNaN2024-02-27 00:00:00
2024-02-286.4200000762939457.2399997711181645.5999999046325685.860000133514404243200.00.00.0SMXTNaN2024-02-28 00:00:00
2024-02-295.7399997711181645.8400001525878914.3000001907348634.889999866485596130000.00.00.0SMXTNaN2024-02-29 00:00:00
2024-03-013.9400000572204595.1500000953674323.7999999523162844.880000114440918485000.00.00.0SMXTNaN2024-03-01 00:00:00
2024-03-044.7300000190734865.0999999046325684.2579998970031744.659999847412109114300.00.00.0SMXTNaN2024-03-04 00:00:00
And I need to create 30 columns (for 30 days) in ipos_df with close price (from  history_data df) n days after IPO.Trying this:

for i in range(1,30):ipos_df['growth_'+str(i)+'d'] = history_data.loc[(history_data['Symbol'].equals(ipos_df['Symbol'])) & ((history_data['Date'] - timedelta(days=i)).equals(ipos_df['Date'])), history_data['Close']].dropna().values[0][0]

Getting this:KeyError: 'False: boolean label can not be used without a boolean index'

Viewing all articles
Browse latest Browse all 16420

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>