In [1]:
import pandas as pd
import numpy as np

# We load Google stock data in a DataFrame
Google_stock = pd.read_csv('C:/Users/Vinay/Python Workspace/Nanodegree/goog-1.csv')

# We print some information about Google_stock
print('Google_stock is of type:', type(Google_stock))
print('Google_stock has shape:', Google_stock.shape)
Google_stock is of type: <class 'pandas.core.frame.DataFrame'>
Google_stock has shape: (3313, 7)
In [3]:
Google_stock.head()
Out[3]:
Date Open High Low Close Adj Close Volume
0 2004-08-19 49.676899 51.693783 47.669952 49.845802 49.845802 44994500
1 2004-08-20 50.178635 54.187561 49.925285 53.805050 53.805050 23005800
2 2004-08-23 55.017166 56.373344 54.172661 54.346527 54.346527 18393200
3 2004-08-24 55.260582 55.439419 51.450363 52.096165 52.096165 15361800
4 2004-08-25 52.140873 53.651051 51.604362 52.657513 52.657513 9257400
In [6]:
Google_stock.head(2)
Out[6]:
Date Open High Low Close Adj Close Volume
0 2004-08-19 49.676899 51.693783 47.669952 49.845802 49.845802 44994500
1 2004-08-20 50.178635 54.187561 49.925285 53.805050 53.805050 23005800
In [4]:
Google_stock.tail()
Out[4]:
Date Open High Low Close Adj Close Volume
3308 2017-10-09 980.000000 985.424988 976.109985 977.000000 977.000000 891400
3309 2017-10-10 980.000000 981.570007 966.080017 972.599976 972.599976 968400
3310 2017-10-11 973.719971 990.710022 972.250000 989.250000 989.250000 1693300
3311 2017-10-12 987.450012 994.119995 985.000000 987.830017 987.830017 1262400
3312 2017-10-13 992.000000 997.210022 989.000000 989.679993 989.679993 1157700
In [5]:
Google_stock.tail(8)
Out[5]:
Date Open High Low Close Adj Close Volume
3305 2017-10-04 957.000000 960.390015 950.690002 951.679993 951.679993 952400
3306 2017-10-05 955.489990 970.909973 955.179993 969.960022 969.960022 1213800
3307 2017-10-06 966.700012 979.460022 963.359985 978.890015 978.890015 1173900
3308 2017-10-09 980.000000 985.424988 976.109985 977.000000 977.000000 891400
3309 2017-10-10 980.000000 981.570007 966.080017 972.599976 972.599976 968400
3310 2017-10-11 973.719971 990.710022 972.250000 989.250000 989.250000 1693300
3311 2017-10-12 987.450012 994.119995 985.000000 987.830017 987.830017 1262400
3312 2017-10-13 992.000000 997.210022 989.000000 989.679993 989.679993 1157700
In [7]:
Google_stock.isnull().any()
Out[7]:
Date         False
Open         False
High         False
Low          False
Close        False
Adj Close    False
Volume       False
dtype: bool
In [8]:
# We get descriptive statistics on our stock data
Google_stock.describe()
Out[8]:
Open High Low Close Adj Close Volume
count 3313.000000 3313.000000 3313.000000 3313.000000 3313.000000 3.313000e+03
mean 380.186092 383.493740 376.519309 380.072458 380.072458 8.038476e+06
std 223.818650 224.974534 222.473232 223.853780 223.853780 8.399521e+06
min 49.274517 50.541279 47.669952 49.681866 49.681866 7.900000e+03
25% 226.556473 228.394516 224.003082 226.407440 226.407440 2.584900e+06
50% 293.312286 295.433502 289.929291 293.029114 293.029114 5.281300e+06
75% 536.650024 540.000000 532.409973 536.690002 536.690002 1.065370e+07
max 992.000000 997.210022 989.000000 989.679993 989.679993 8.276810e+07
In [9]:
# We get descriptive statistics on a single column of our DataFrame
Google_stock['Adj Close'].describe()
Out[9]:
count    3313.000000
mean      380.072458
std       223.853780
min        49.681866
25%       226.407440
50%       293.029114
75%       536.690002
max       989.679993
Name: Adj Close, dtype: float64
In [10]:
# We print information about our DataFrame  
print()
print('Maximum values of each column:\n', Google_stock.max())
print()
print('Minimum Close value:', Google_stock['Close'].min())
print()
print('Average value of each column:\n', Google_stock.mean())
Maximum values of each column:
 Date         2017-10-13
Open                992
High             997.21
Low                 989
Close            989.68
Adj Close        989.68
Volume         82768100
dtype: object

Minimum Close value: 49.681866

Average value of each column:
 Open         3.801861e+02
High         3.834937e+02
Low          3.765193e+02
Close        3.800725e+02
Adj Close    3.800725e+02
Volume       8.038476e+06
dtype: float64
In [11]:
# We display the correlation between columns
Google_stock.corr()
Out[11]:
Open High Low Close Adj Close Volume
Open 1.000000 0.999904 0.999845 0.999745 0.999745 -0.564258
High 0.999904 1.000000 0.999834 0.999868 0.999868 -0.562749
Low 0.999845 0.999834 1.000000 0.999899 0.999899 -0.567007
Close 0.999745 0.999868 0.999899 1.000000 1.000000 -0.564967
Adj Close 0.999745 0.999868 0.999899 1.000000 1.000000 -0.564967
Volume -0.564258 -0.562749 -0.567007 -0.564967 -0.564967 1.000000
In [21]:
# We load Fake Company data in a DataFrame
data = pd.read_csv('C:/Users/Vinay/Python Workspace/Nanodegree/fake_company.csv')
data
Out[21]:
Year Name Department Age Salary
0 1990 Alice HR 25 50000
1 1990 Bob RD 30 48000
2 1990 Charlie Admin 45 55000
3 1991 Alice HR 26 52000
4 1991 Bob RD 31 50000
5 1991 Charlie Admin 46 60000
6 1992 Alice HR 27 60000
7 1992 Bob RD 32 52000
8 1992 Charlie Admin 47 62000
In [22]:
# We display the total amount of money spent in salaries each year
data.groupby(['Year'])['Salary'].sum()
Out[22]:
Year
1990    153000
1991    162000
1992    174000
Name: Salary, dtype: int64
In [23]:
# We display the average salary per year
data.groupby(['Year'])['Salary'].mean()
Out[23]:
Year
1990    51000
1991    54000
1992    58000
Name: Salary, dtype: int64
In [24]:
# We display the total salary each employee received in all the years they worked for the company
data.groupby(['Name'])['Salary'].sum()
Out[24]:
Name
Alice      162000
Bob        150000
Charlie    177000
Name: Salary, dtype: int64
In [25]:
# We display the salary distribution per department per year.
data.groupby(['Year', 'Department'])['Salary'].sum()
Out[25]:
Year  Department
1990  Admin         55000
      HR            50000
      RD            48000
1991  Admin         60000
      HR            52000
      RD            50000
1992  Admin         62000
      HR            60000
      RD            52000
Name: Salary, dtype: int64
In [ ]: