250x250
반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 지방사람이보는서울사람
- 꼭읽어봐야할책
- 서울로가자
- OpenCV
- Python
- 훌륭한모국어
- 성선택
- 중용
- Git
- UPSERT
- 헬레나크로닌
- Face Detection
- 일일투자금액
- todolist
- linux명령어
- 다산의마지막습관
- 나만의주식5법칙
- 공작과개미
- 클라우드
- git 업로드
- 독후감
- delete
- ChatGPT
- MySQL
- db
- Django
- 네인생우습지않다
- 옹졸함
- 비밀번호변경
- php
Archives
- Today
- Total
Terry Very Good
[ChatGPT] colab에서 ChatGPT에게 물어보며 FinanceDataReader 사용하여 주식 데이터 가져오기( 티커를 리스트로 만든 다음 어제 오늘 사이의 주가 현황을 엑셀로 보여주는 코드) 본문
신기술 습득/ChatGPT
[ChatGPT] colab에서 ChatGPT에게 물어보며 FinanceDataReader 사용하여 주식 데이터 가져오기( 티커를 리스트로 만든 다음 어제 오늘 사이의 주가 현황을 엑셀로 보여주는 코드)
테리베리 2023. 4. 11. 15:15728x90
반응형
https://colab.research.google.com/
Google Colaboratory
colab.research.google.com
1. 아래와 같이 colab에서 새 노트를 만들고, hello world! 를 출력해보자
2. KRX 종목을 가져와서 출력하고, 삼성전자의 21년간 주가현황을 출력하고 엑셀로 저장해줘!
# finance-datareader 다운로드
!pip install finance-datareader
# 국내 증시 데이터 수집 예시
import FinanceDataReader as fdr
# KRX 종목 코드 가져오기
krx = fdr.StockListing('KRX')
print(krx.head())
# 삼성전자(005930)의 2021년 데이터 가져오기
samsung = fdr.DataReader('005930', '2021-01-01', '2021-12-31')
print(samsung.head())
# 엑셀 저장
samsung.to_excel('삼성전자2021.xlsx')
samsung.to_csv('삼성전자2021.csv')
3. 내가 원하는 티커를 리스트로 담은 다음, 그 주식의 어제/오늘 사이의 주가를 알려줘!
import pandas as pd
import FinanceDataReader as fdr
from datetime import datetime, timedelta
# Define the item codes
item_code_list = ['AAPL', 'GOOGL', 'AMZN']
# Define yesterday's date
yesterday = (datetime.today() - timedelta(days=1)).strftime('%Y-%m-%d')
# Initialize an empty list to store the dataframes
df_list = []
# Loop through the item codes
for item in item_code_list:
# Get the stock price data for yesterday
df = fdr.DataReader(item, yesterday, yesterday)
# Add the ticker name as a new column
df['Ticker'] = item
# Append the dataframe to the list
df_list.append(df)
# Concatenate the dataframes into a single dataframe
result_df = pd.concat(df_list)
# Save the result to an Excel file
result_df.to_excel('미국주식.xlsx', index=False)
(잡상식: 파이썬은 내가짜려고하지말고, 남이짠거 써라. numpy같은거 써야 최소 200배 빠름)
728x90
반응형
'신기술 습득 > ChatGPT' 카테고리의 다른 글
copilot 활용 기초 교육 1 (워드, 엑셀, 파워포인트, 아웃룩, 팀즈) (1) | 2024.07.30 |
---|---|
[ChatGPT] ChatGPT로 VBA를 자유롭게 빠르게 사용해보자! (0) | 2023.04.11 |
[chatGPT] 엑셀 활용법( 엑셀 데이터에 맞는 함수 물어보는 방법) (0) | 2023.04.11 |
[ChatGPT] chatGPT를 똑똑하게 사용할 수 있는 확장프로그램들(프롬프트지니, WebChatGPT) (0) | 2023.04.11 |