Python 3 Yahoo Finance API to Export All Companies Financial Stock Market Data & Save as Excel File
166 views
Jun 1, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-yahoo-finance-api-to-export-all-companies-financial-stock-data-save-as-excel-xlsx-file/
View Video Transcript
0:00
uh hello guys welcome to this video So
0:02
in this video I will show you a fi uh
0:04
python package which will actually fetch
0:07
the financial market stock market data
0:10
of all the top 100 companies in the
0:12
world It's using Yahoo Finance uh API
0:17
and it provides you a free module inside
0:19
Python where you can use this uh API in
0:22
the background and fetch using the
0:24
technique of web scraping So the this is
0:27
actually the simple Python script It
0:29
will save this all this data inside in
0:31
this Excel file Here you will see the
0:33
actual column names This is address of
0:35
the company which is city state zip code
0:38
country of the company phone number
0:41
website as well It will also fetch the
0:44
industry of the company As you can see
0:46
here it is fetching all
0:48
this companies here
0:53
You'll see
0:55
that all set of financial stock market
0:59
data which is relevant here it all
1:01
fetches for the top 100 companies here
1:04
you will see that so let me show you the
1:06
package here uh this is uh y finance if
1:10
you just go to the python website here
1:12
just search for this package here pip
1:14
install y finance just install this I've
1:16
already installed it and the second
1:18
package is pandas which is used for data
1:21
analysis also you need to install this
1:23
as well by executing this command So I
1:26
have given all the script in the
1:28
description of the video So just now
1:30
create a simple app py
1:32
file and uh now first of all you need to
1:35
import the necessary packages like this
1:39
yness as y Secondly we also need to
1:44
import the pandas package And here you
1:48
just need to create the tickers by which
1:51
you actually this is shorthand notation
1:55
for each company in the world
1:57
So you can find for any company the
2:01
tickers value So I will just paste this
2:04
inside this array
2:07
So Google ticker is this shorthand form
2:09
like this Amazon this is Meta Nvidia So
2:13
we'll see like this So you put this now
2:17
and using these stickers value you will
2:19
be fetching the financial stock market
2:21
data So just create a simple data
2:23
variable and we will be loop looping
2:25
through this array here like
2:31
this and using this ticker value we will
2:34
be fetching the
2:36
data using this package here Yahoo
2:39
finance package it contains this
2:41
function ticker and here you will pass
2:43
your ticker value and grab the
2:48
info So you can print out this data here
2:51
So this will contain all the properties
2:55
of the data that you
2:58
want So here you will put the
3:11
exception So now if you if you see here
3:14
if you execute this one by one it will
3:16
fetch the data here You will see each
3:20
set of data has is fetching here And now
3:24
we just need to store this
3:27
data inside Excel file rather than
3:31
printing it out
3:32
So what we will do after
3:35
this fetching this right here we'll be
3:39
storing
3:47
it and we'll be appending this data
3:52
here So like this after that we will
3:56
convert all this data into a data frame
3:58
by using the pandas library like this
4:00
This is a function here which is data
4:02
frame and passing this data to
4:07
it Uh after that we just need to create
4:10
a excel file For creating the excel file
4:13
here we will use the pandas library once
4:15
again So we'll just name this whatever
4:18
you want to do this So let me just name
4:20
it xls and this contains this function
4:25
to excel we will convert this output
4:33
file So now what happens so you it will
4:37
go one by one using the ticker
4:39
value It will fetch the data and then
4:42
store this inside that Excel file So let
4:45
me just restart this once
4:47
again It will do this for all the 100
4:50
companies out there one by one
4:56
So you just need to wait and after some
4:59
time it will create that Excel file So
5:01
it will go through each company here 1 2
5:04
3 So this for loop will run here 100
5:07
times After 100 successful iterations it
5:10
will create this Excel file and save
5:12
this inside your location So it's a very
5:16
useful
5:17
package You can do this unlimited number
5:19
of time There is no such restriction out
5:22
there using this package It uses Yahoo
5:25
Finance API in the background to
5:27
download the financial market
5:30
data So it downloaded the latest
5:34
data from this API Yahoo Finance
5:39
API By the way this API is not free but
5:42
this package allows you to use this for
5:44
free Just getting this market data for
5:48
completely free
5:50
So you will see it has created this
5:52
excel file and all the market data has
5:55
been
5:56
fetched all the properties here city
5:59
state zip country phone number website
6:01
what is the industry of the company you
6:04
can see it fetches all the
6:06
data so if you need the full script here
6:09
you can go to the description and copy
6:10
paste all the source code from my
6:12
website blog and thank you very much for
6:15
watching this video please hit that like
6:17
button subscribe the channel and also
6:19
Check out my website uh
6:21
freemediattools.com
6:23
uh which contains thousands of tools
#Investing
#Scripting Languages
#Stocks & Bonds