avatarMisbah Ul Haq Syed

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

1238

Abstract

me Python code to retrieve Tesla stock prices from 2022 using Yahoo Finance. I want the output to be in a csv file called ‘stock_prices.csv’ The CSV file mys have a column named “Date” representing the dates and a column named “Price” representing the stock prices.”</p><p id="e110">And then the output will be:</p><figure id="f70f"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*4cgK5TnDtjHmV_MaFnGNCw.png"><figcaption></figcaption></figure><h1 id="df02">Step 2: Copy this code using the botton “copy code” at the top right</h1><h1 id="f854">Step 3: Paste the code in Google Colab</h1><p id="38fa">Navigate to <a href="https://colab.research.google.com/">https://colab.research.google.com/</a> . The create a new notebook by logging in using your Google account.</p><p id="0eee">This is the full code I got from Chat GPT.</p><p id="77be">But remember, you can customise the prompt to get any other stock.</p><div id="eeb1"><pre><span class="hljs-keyword">import</span> yfinance <span class="hljs-keyword">as</span> yf <span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd

<span class="hljs-comment"># Define the stock symbol and the time range for which you want the data</span> sym

Options

bol = <span class="hljs-string">"TSLA"</span> start_date = <span class="hljs-string">"2022-01-01"</span> end_date = <span class="hljs-string">"2022-12-31"</span>

<span class="hljs-comment"># Fetch the stock data using Yahoo Finance</span> stock_data = yf.download(symbol, start=start_date, end=end_date)

<span class="hljs-comment"># Extract the 'Date' and 'Close' columns from the stock data</span> stock_data = stock_data[[<span class="hljs-string">'Close'</span>]].reset_index()

<span class="hljs-comment"># Rename the columns to 'Date' and 'Price'</span> stock_data.columns = [<span class="hljs-string">'Date'</span>, <span class="hljs-string">'Price'</span>]

<span class="hljs-comment"># Save the stock data to a CSV file</span> stock_data.to_csv(<span class="hljs-string">'stock_prices.csv'</span>, index=<span class="hljs-literal">False</span>)

<span class="hljs-built_in">print</span>(<span class="hljs-string">"Stock data saved to 'stock_prices.csv'"</span>)</pre></div><h1 id="dbca">Step 4: Use the CSV file with the stock data</h1><p id="db5f">As simple as that!</p><figure id="4c88"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*lpNgMNRzr3oNIaAX.png"><figcaption></figcaption></figure></article></body>

100 DAYS WRITING CHALLENGE

How To Plan The Writing Challenge

This is what I did in my first week — Episode 8

Photo by Estée Janssens on Unsplash

There is a debate in Medium of quality over quantity. When you have committed to the writing challenge, you are definitely in for the quantity. But who says that you have to sacrifice the quality. Easier said than done, isn't it? Sure is! But once onboard, you need to make a strategy to run through the 100 miles of the marathon with no pit stops.

Okay, this is what you could do in the writing challenge to make it more productive and entertaining. Think of a theme or subject and write multiple stories within the scope. Once you or your readers get bored with it, take another niche and go for it. Like I talked about the cities where I have lived for one year or more. Hope it was worth a try.

These are the top 5 cities that are closest to me:

Karachi, my identity. This is where I was born, completed my studies, got married, and started my first job.

Sharjah, my first international move. Went there with my wife and two little kids. Emotionally derailing in the beginning but later proved to be a splendid choice. The time spent there is unforgettable and I cherish every moment.

Dubai, the love of my life. This is where I spent over 8 years. We travelled to all 7 U.A.E. states, made a lot of friends, and enjoyed ourselves a lot more than words can ever describe.

Riyadh, my two-time love affair. First, I lived there when I was 4 years old, and a second time when I turned over 40 — ironic isn't it? Find out more…

Toulouse, my home for the last 5 years. I never knew this place actually existed. Now, I never want to leave it.

This is all about my first week on the challenge. I am enjoying the ride so far. You can also craft your journey in a similar fashion on the same or different topics.

I hope you enjoyed today’s episode. See you tomorrow!

Writer
100DayChallenge
Writing Tips
Cities
Advice
Recommended from ReadMedium