FINC-241 Lecture Notes - Lecture 4: Matplotlib, Serif

5 views9 pages
Published on 27 Feb 2020
School
Georgetown University
Department
Finance
Course
FINC-241
Professor
2/27/2020 Untitled1
file:///C:/Users/16318/Downloads/Untitled1.html 1/9
In [1]:
from pylab import plt
plt.style.use('seaborn')
import matplotlib as mpl
mpl.rcParams['font.family'] = 'serif'
In [2]:
import numpy as np
import pandas as pd
In [3]:
df = pd.DataFrame([10, 20, 30, 40], columns=['numbers'],
index=['a', 'b', 'c', 'd'])
df
In [4]:
df.index
In [5]:
df.columns
In [6]:
df.loc['c']
In [7]:
df.loc[['a', 'd']]
In [8]:
df.loc[df.index[1:3]]
Out[3]:
numbers
a10
b20
c30
d40
Out[4]:
Index([u'a', u'b', u'c', u'd'], dtype='object')
Out[5]:
Index([u'numbers'], dtype='object')
Out[6]:
numbers 30
Name: c, dtype: int64
Out[7]:
numbers
a10
d40
Out[8]:
numbers
b20
c30
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 9 pages and 3 million more documents.

Already have an account? Log in
2/27/2020 Untitled1
file:///C:/Users/16318/Downloads/Untitled1.html 2/9
In [9]:
df.sum()
In [10]:
df.apply(lambda x: x ** 2)
In [11]:
df ** 2
In [12]:
df['floats'] = (1.5, 2.5, 3.5, 4.5)
df
In [13]:
df['floats']
Out[9]:
numbers 100
dtype: int64
Out[10]:
numbers
a100
b400
c900
d1600
Out[11]:
numbers
a100
b400
c900
d1600
Out[12]:
numbers floats
a10 1.5
b20 2.5
c30 3.5
d40 4.5
Out[13]:
a 1.5
b 2.5
c 3.5
d 4.5
Name: floats, dtype: float64
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 9 pages and 3 million more documents.

Already have an account? Log in
2/27/2020 Untitled1
file:///C:/Users/16318/Downloads/Untitled1.html 3/9
In [14]:
df['names'] = pd.DataFrame(['Yves', 'Guido', 'Felix', 'Francesc'], index=['d',
'a', 'b', 'c'])
df
In [15]:
df.append({'numbers': 100, 'floats': 5.75, 'names': 'Henry'},ignore_index=True
)
In [16]:
df = df.append(pd.DataFrame({'numbers': 100, 'floats': 5.75,'names': 'Henry'},
index=['z']),sort=False)
df
In [17]:
df.join(pd.DataFrame([1, 4, 9, 16, 25],index=['a', 'b', 'c', 'd', 'y'],columns
=['squares',]))
Out[14]:
numbers floats names
a10 1.5 Guido
b20 2.5 Felix
c30 3.5 Francesc
d40 4.5 Yves
Out[15]:
numbers floats names
010 1.50 Guido
120 2.50 Felix
230 3.50 Francesc
340 4.50 Yves
4100 5.75 Henry
Out[16]:
numbers floats names
a10 1.50 Guido
b20 2.50 Felix
c30 3.50 Francesc
d40 4.50 Yves
z100 5.75 Henry
Out[17]:
numbers floats names squares
a10 1.50 Guido 1.0
b20 2.50 Felix 4.0
c30 3.50 Francesc 9.0
d40 4.50 Yves 16.0
z100 5.75 Henry NaN
Unlock document

This preview shows pages 1-3 of the document.
Unlock all 9 pages and 3 million more documents.

Already have an account? Log in

Document Summary

In [1]: from pylab import plt plt. style. use("seaborn") import matplotlib as mpl mpl. rcparams["font. family"] = "serif" In [2]: import numpy as np import pandas as pd. In [3]: df = pd. dataframe([10, 20, 30, 40], columns=["numbers"], index=["a", "b", "c", "d"]) df. In [12]: df["floats"] = (1. 5, 2. 5, 3. 5, 4. 5) df. In [14]: df["names"] = pd. dataframe(["yves", "guido", "felix", "francesc"], index=["d", Out[14]: numbers floats names a b c d. In [15]: df. append({"numbers": 100, "floats": 5. 75, "names": "henry"},ignore_index=true. In [16]: df = df. append(pd. dataframe({"numbers": 100, "floats": 5. 75,"names": "henry"}, index=["z"]),sort=false) df. Out[16]: numbers floats names a b c d z. In [17]: df. join(pd. dataframe([1, 4, 9, 16, 25],index=["a", "b", "c", "d", "y"],columns. Out[17]: numbers floats names squares a b c d z. In [18]: df = df. join(pd. dataframe([1, 4, 9, 16, 25],index=["a", "b", "c", "d", "y"],co lumns=["squares",]),how="outer") df. Out[18]: numbers floats names squares a b c d y z. In [23]: df. columns = ["no1", "no2", "no3", "no4"] df. In [25]: dates = pd. date_range("2015-1-1", periods=9, freq="m") dates.

Get OneClass Grade+

Unlimited access to all notes and study guides.

YearlyMost Popular
75% OFF
$9.98/m
Monthly
$39.98/m
Single doc
$39.98

or

You will be charged $119.76 upfront and auto renewed at the end of each cycle. You may cancel anytime under Payment Settings. For more information, see our Terms and Privacy.
Payments are encrypted using 256-bit SSL. Powered by Stripe.