# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
import numpy as np
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
import os
sns.set_style("darkgrid")
%matplotlib inline
df = pd.read_csv('D:/Datasets/nifty.csv')
df
Company Name | Symbol | Industry | Series | Open | High | Low | Previous Close | Last Traded Price | Change | Percentage Change | Share Volume | Value (Indian Rupee) | 52 Week High | 52 Week Low | 365 Day Percentage Change | 30 Day Percentage Change | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 3M India Ltd. | 3MINDIA | Diversified | EQ | 21950.00 | 21999.00 | 21126.05 | 21854.05 | 21575.00 | -279.05 | -1.28 | 4159 | 8.965357e+07 | 27800.00 | 17273.00 | -10.18 | 8.22 |
1 | Aarti Drugs Ltd. | AARTIDRUGS | Healthcare | EQ | 400.50 | 401.80 | 394.10 | 403.85 | 400.00 | -3.85 | -0.95 | 31782 | 1.262731e+07 | 749.75 | 378.00 | -42.92 | -5.10 |
2 | Aavas Financiers Ltd. | AAVAS | Financial Services | EQ | 1997.10 | 2004.05 | 1894.50 | 2015.45 | 1943.15 | -72.30 | -3.59 | 150704 | 2.907728e+08 | 3340.00 | 1815.00 | -25.69 | -9.39 |
3 | ABB India Ltd. | ABB | Capital Goods | EQ | 2260.35 | 2311.50 | 2260.35 | 2300.90 | 2280.00 | -20.90 | -0.91 | 97053 | 2.210935e+08 | 2487.85 | 1618.05 | 27.25 | -5.21 |
4 | Abbott India Ltd. | ABBOTINDIA | Healthcare | EQ | 18700.40 | 19200.00 | 18605.00 | 18760.40 | 19199.80 | 439.40 | 2.34 | 12396 | 2.346770e+08 | 23934.45 | 15514.00 | 11.61 | 5.84 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
496 | Zensar Technolgies Ltd. | ZENSARTECH | Information Technology | EQ | 273.15 | 273.55 | 268.40 | 272.10 | 270.00 | -2.10 | -0.77 | 186578 | 5.046748e+07 | 587.00 | 246.65 | -12.61 | -11.02 |
497 | ZF Commercial Vehicle Control Systems India Ltd. | ZFCVINDIA | Automobile and Auto Components | EQ | 7748.00 | 7900.00 | 7525.30 | 7716.60 | 7680.00 | -36.60 | -0.47 | 12790 | 9.884624e+07 | 8780.05 | 6793.30 | - | 1.43 |
498 | Zomato Ltd. | ZOMATO | Consumer Services | EQ | 54.15 | 56.70 | 52.55 | 53.85 | 56.00 | 2.15 | 3.99 | 112078641 | 6.193466e+09 | 169.00 | 50.05 | - | -27.86 |
499 | Zydus Lifesciences Ltd. | ZYDUSLIFE | Healthcare | EQ | 356.90 | 364.05 | 354.30 | 357.00 | 364.00 | 7.00 | 1.96 | 862373 | 3.100145e+08 | 651.90 | 319.00 | - | -5.64 |
500 | Zydus Wellness Ltd. | ZYDUSWELL | Fast Moving Consumer Goods | EQ | 1635.00 | 1635.00 | 1605.00 | 1636.85 | 1627.00 | -9.85 | -0.60 | 10803 | 1.749567e+07 | 2476.85 | 1430.00 | -22.08 | 6.25 |
501 rows × 17 columns
df.head()
Company Name | Symbol | Industry | Series | Open | High | Low | Previous Close | Last Traded Price | Change | Percentage Change | Share Volume | Value (Indian Rupee) | 52 Week High | 52 Week Low | 365 Day Percentage Change | 30 Day Percentage Change | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 3M India Ltd. | 3MINDIA | Diversified | EQ | 21950.00 | 21999.00 | 21126.05 | 21854.05 | 21575.00 | -279.05 | -1.28 | 4159 | 8.965357e+07 | 27800.00 | 17273.00 | -10.18 | 8.22 |
1 | Aarti Drugs Ltd. | AARTIDRUGS | Healthcare | EQ | 400.50 | 401.80 | 394.10 | 403.85 | 400.00 | -3.85 | -0.95 | 31782 | 1.262731e+07 | 749.75 | 378.00 | -42.92 | -5.10 |
2 | Aavas Financiers Ltd. | AAVAS | Financial Services | EQ | 1997.10 | 2004.05 | 1894.50 | 2015.45 | 1943.15 | -72.30 | -3.59 | 150704 | 2.907728e+08 | 3340.00 | 1815.00 | -25.69 | -9.39 |
3 | ABB India Ltd. | ABB | Capital Goods | EQ | 2260.35 | 2311.50 | 2260.35 | 2300.90 | 2280.00 | -20.90 | -0.91 | 97053 | 2.210935e+08 | 2487.85 | 1618.05 | 27.25 | -5.21 |
4 | Abbott India Ltd. | ABBOTINDIA | Healthcare | EQ | 18700.40 | 19200.00 | 18605.00 | 18760.40 | 19199.80 | 439.40 | 2.34 | 12396 | 2.346770e+08 | 23934.45 | 15514.00 | 11.61 | 5.84 |
NIFTY 500 is India’s first broad-based stock market index of the Indian stock market. It contains top 500 listed companies on the NSE. The NIFTY 500 index represents about 96.1% of free float market capitalization and about 96.5% of the total turnover on the National Stock Exchange (NSE).
NIFTY 500 companies are disaggregated into 72 industry indices.Industry weights in the index reflect industry weights in the market. For example, if the banking sector has a 5% weight in the universe of stocks traded on the NSE, banking stocks in the index would also have an approximate representation of 5% in the index.NIFTY 500 can be used for a variety of purposes such as benchmarking fund portfolios, launching of index funds, ETFs and other structured products
NIFTY 500/S&P CNX 500 Type:Stock market index Location:Mumbai, India Owner:National Stock Exchange of India Currency:Indian Rupee Website:Nifty500
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 501 entries, 0 to 500 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Company Name 501 non-null object 1 Symbol 501 non-null object 2 Industry 501 non-null object 3 Series 501 non-null object 4 Open 501 non-null float64 5 High 501 non-null float64 6 Low 501 non-null float64 7 Previous Close 501 non-null float64 8 Last Traded Price 501 non-null float64 9 Change 501 non-null object 10 Percentage Change 501 non-null object 11 Share Volume 501 non-null int64 12 Value (Indian Rupee) 501 non-null float64 13 52 Week High 501 non-null float64 14 52 Week Low 501 non-null float64 15 365 Day Percentage Change 501 non-null object 16 30 Day Percentage Change 501 non-null object dtypes: float64(8), int64(1), object(8) memory usage: 66.7+ KB
The Open and Previous Close segments show the opening and shutting cost of the stocks on a specific day Industry Sectors to which the stocks has a place The High and Low segments give the most elevated and the least cost for the stock on a specific day, individually. The Share Volume section lets us know the all out volume of stocks exchanged on a specific day. 52 Week High and Low colums Provides the yearly high and low assumed worth of the stock
df.isnull().sum()
Company Name 0 Symbol 0 Industry 0 Series 0 Open 0 High 0 Low 0 Previous Close 0 Last Traded Price 0 Change 0 Percentage Change 0 Share Volume 0 Value (Indian Rupee) 0 52 Week High 0 52 Week Low 0 365 Day Percentage Change 0 30 Day Percentage Change 0 dtype: int64
df.duplicated().sum()
0
df.nunique()
Company Name 501 Symbol 501 Industry 21 Series 2 Open 492 High 495 Low 493 Previous Close 495 Last Traded Price 493 Change 372 Percentage Change 354 Share Volume 501 Value (Indian Rupee) 501 52 Week High 497 52 Week Low 494 365 Day Percentage Change 441 30 Day Percentage Change 458 dtype: int64
Object Values
object_dtype = df.select_dtypes(include=object)
object_dtype.columns
Index(['Company Name', 'Symbol', 'Industry', 'Series', 'Change', 'Percentage Change', '365 Day Percentage Change', '30 Day Percentage Change'], dtype='object')
object_dtype = df.select_dtypes(exclude=object)
object_dtype.columns
Index(['Open', 'High', 'Low', 'Previous Close', 'Last Traded Price', 'Share Volume', 'Value (Indian Rupee)', '52 Week High', '52 Week Low'], dtype='object')
sns.distplot(x = df['Open'])
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning)
<AxesSubplot:ylabel='Density'>
sns.distplot(x = df['High'])
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning)
<AxesSubplot:ylabel='Density'>
sns.distplot(x = df['Open'])
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning)
<AxesSubplot:ylabel='Density'>
sns.distplot(x = df['Previous Close'])
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms). warnings.warn(msg, FutureWarning)
<AxesSubplot:ylabel='Density'>
sns.countplot(df['Industry'])
plt.xticks(rotation=90)
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\_decorators.py:36: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation. warnings.warn(
(array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]), [Text(0, 0, 'Diversified'), Text(1, 0, 'Healthcare'), Text(2, 0, 'Financial Services'), Text(3, 0, 'Capital Goods'), Text(4, 0, 'Consumer Services'), Text(5, 0, 'Construction Materials'), Text(6, 0, 'Metals & Mining'), Text(7, 0, 'Power'), Text(8, 0, 'Services'), Text(9, 0, 'Fast Moving Consumer Goods'), Text(10, 0, 'Oil Gas & Consumable Fuels'), Text(11, 0, 'Information Technology'), Text(12, 0, 'Chemicals'), Text(13, 0, 'Textiles'), Text(14, 0, 'Automobile and Auto Components'), Text(15, 0, 'Consumer Durables'), Text(16, 0, 'Telecommunication'), Text(17, 0, 'Realty'), Text(18, 0, 'Forest Materials'), Text(19, 0, 'Construction'), Text(20, 0, 'Media Entertainment & Publication')])
sns.countplot(df['Series'])
C:\ProgramData\Anaconda3\lib\site-packages\seaborn\_decorators.py:36: FutureWarning: Pass the following variable as a keyword arg: x. From version 0.12, the only valid positional argument will be `data`, and passing other arguments without an explicit keyword will result in an error or misinterpretation. warnings.warn(
<AxesSubplot:xlabel='Series', ylabel='count'>
fx = df[['High','Low']].plot(figsize=(20,7))
fx.set_title("High vs Low",fontsize=25)
Text(0.5, 1.0, 'High vs Low')
fx = df[['Open','Previous Close']].plot(figsize=(20,5))
fx.set_title("Open Vs Previous Close",fontsize=20)
Text(0.5, 1.0, 'Open Vs Previous Close')
fx = df[['Open','Last Traded Price']].plot(figsize=(20,5))
fx.set_title("Open Vs Last Traded Price",fontsize=20)
Text(0.5, 1.0, 'Open Vs Last Traded Price')
sns.jointplot(x='Open', y='Previous Close', data=df, kind="reg", truncate=False, color="m", height=7);
sns.jointplot(x='High', y='Low', data=df, kind="reg", truncate=False, color="m", height=7);
sns.jointplot(x= 'Share Volume', y= 'Value (Indian Rupee)', data=df, kind="reg", truncate=False, color="m", height=7);
sns.jointplot(x= 'High', y= 'Value (Indian Rupee)', data=df, kind="reg", truncate=False, color="m", height=7);
sns.jointplot(x= 'Low', y= 'Value (Indian Rupee)', data=df, kind="reg", truncate=False, color="m", height=7);
sns.pairplot(df)
plt.show()
plt.figure(figsize = (10, 10))
cor=df.corr()
sns.heatmap(cor, annot = True, cmap="YlGnBu")
plt.show()
fig, axs = plt.subplots(5, 2, figsize=(8,10))
fig.tight_layout(pad=4.0)
features = ['Open', 'High', 'Low', 'Previous Close', 'Last Traded Price','Share Volume', 'Value (Indian Rupee)', '52 Week High', '52 Week Low']
for f,ax in zip(features,axs.ravel()):
ax=sns.boxplot(ax=ax,data=df,y=df[f])
ax.set_title('Feature:'+ f)
df.plot(subplots=True,figsize=(29,15))
array([<AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>, <AxesSubplot:>], dtype=object)