Skip to content

Commit

Permalink
changed 'LIN' insert into a single line of code
Browse files Browse the repository at this point in the history
  • Loading branch information
fja05680 committed Feb 22, 2021
1 parent e068364 commit 57fc34b
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions sp500_historical.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,22 @@
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# add LIN after 2018-10-31\n",
"def _add_symbol(row, symbol, date):\n",
" if row.name > date:\n",
" row.tickers.append(symbol)\n",
" return row.tickers\n",
"df['tickers'] = df.apply(_add_symbol, symbol='LIN', date='2018-10-31', axis=1)"
"df.loc[df.index > '2018-10-31', 'tickers'].apply(lambda x: x.append('LIN'))\n",
"'LIN' in df['tickers'].values[-1]"
]
},
{
Expand Down Expand Up @@ -973,6 +981,21 @@
"filename = 'S&P 500 Historical Components & Changes({}).csv'.format(dt_string)\n",
"df.to_csv(filename)"
]
},
{
"cell_type": "raw",
"metadata": {
"ExecuteTime": {
"end_time": "2020-04-21T03:37:52.430487Z",
"start_time": "2020-04-21T03:37:52.246982Z"
}
},
"source": [
"now = datetime.now()\n",
"dt_string = now.strftime('%m-%d-%Y') # mm-dd-YYYY\n",
"filename = 'S&P 500 Historical Components & Changes({}).csv'.format(dt_string)\n",
"df.to_csv(filename)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 57fc34b

Please sign in to comment.