100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4.2 TrustPilot
logo-home
Samenvatting

Summary Python courses programming for economists

Beoordeling
-
Verkocht
3
Pagina's
13
Geüpload op
08-02-2021
Geschreven in
2019/2020

This is a summary of the "Python"-part of the course: Programming for economists given at Tilburg University. The documents contains a summary of the theory and codes needed to do the exercises in Python.











Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Documentinformatie

Geüpload op
8 februari 2021
Bestand laatst geupdate op
8 februari 2021
Aantal pagina's
13
Geschreven in
2019/2020
Type
Samenvatting

Voorbeeld van de inhoud

Programming for economists – Python courses
Introduction to Python

Types of variables

Int = integer: gehele getallen
Float = floating point: kommagetallen
Str = string: tekst -> “”
Bool = boolean: True or False

Check the type: type(variable)
Convert values into any type: str(), int(), etc.


Pyhton Lists
List = [[a, “a”], [b, “b”], [c, “c”]]

Subsetting lists
List = [0,1,2,3,4,5]
list[-1] : last element of the index = [5]
list[3:5] -> [3,4]  [start=inclusive:end=exclusive]

Slicing
list[3:]  [3,4,5]
list[:3]  [0,1,2]
print(list[1] + list[3])  4

list2 = [[1,2,3],[3,4,5],[6,7,8]]
x[2][:2]  [6,7]

Adding and removing elements
list_ext = list + [6,7]
del(list_ext[0]) #note: all indexes change immediatly after
list_ext[1]= “a” this call, so ‘1’ is now [0] and ‘2’ is [1]
 [1,a,3,4,5,6,7]

If you want to make a copy of list ‘list_copy’ and prevent that changes
in this list also affect ‘list’  list_copy = list(list)

Functions and packages for Python Lists
max(), min(), mean(), median(), len(), type()
round(number, ndigits) e.g. round(7.27,1)  7.3
complex([real[,imag]])
sorted(iterable, reverse = True)
 return a new sorted list from the items in iterable
(reverse=True, big -> small)
list.index(), list.count(), list.append(), list.remove(),
list.reverse()  reverses the order of the elements in the list
str.capitalize(), str.replace(), str.upper()
Numpy (Numeric Python)

,Import numpy as np
! Numpy arrays: contain only one type (int,floats, etc.)
! If you call: numpy_array + numpy_array it sums the firts element of
the first list with the first element of the second list
e.g. list = [1,2,3] ; np_array = np.array([1,2,3])
* list + list  [1,2,3,1,2,3]
* np_array + np_array  [2,4,6]

Numpy subsetting
np_array = np.array([1,2,3,4,5])
np_array > 2  array([False, False, True, True, True])
np_array[np_array>2]  array([3,4,5])

2D Numpy Arrays
Multiple rows/columns: np_2d.shape=4,2 means 4 rows w/ 2 elements each

np_2d[0][2] or np_2d[0,2] selects the third element of the first row
np_2d[:,1:3] selects the second and third element of every row
np_2d[1,:] selects only the entire second row

Basic statistics
np.mean(np_array)
np.median(np_array)
np.std(np_array)
np.corrcoef(np_array)

set an index to a np_array:
e.g. np_positions[‘GK’, ‘M’, ‘A’]
np_heights[191,184,185,…,179]

* gk_heights = np_heights[np_positions == ‘GK’]
This call prints the heights of the goalkeepers (GK)

* gk_heights = np_heights[np_positions != ‘GK’]
This call prints the heights of all other players then GK

, Intermediate Python

Matplotlib
Import matplotlib.pyplot as plt

plt.plot(x,y) ; plt.scatter()
plt.show()

put the x-axis on a log scale: plt.xscale(‘log’)

Histogram

plt.hist(x, bins=#, range=None, normed=False/True, weights=None)
plt.show()

plt.clf(): cleans up so that you can start fresh -> after plt.show()

Customization

plt.xlabel(‘’)
plt.ylabel(‘’)
plt.title(‘’)
plt.yticks([0,2,4])
plt.xticks([])

Add more data: y = [ , , ] + y ; x = [ , , ] + x

plt.scatter(x,y, s= np.array(), c = list, alpha = )
s = size (array)
c = colour (list/array)
alpha = transparancy

plt.grid(True)  gridlines are shown in the plot

Dictionaries in Python

create a dictionary: dict = { ‘’:{‘’: ,‘’: ,‘’:} }
data sorted in alphabetical order
if data belongs together europe = {’spain’:’madrid’, ‘france’:’paris’}
add data to dictionary: europe[‘italy’] = ‘rome’
dict[‘key’] = ‘value’  {‘key’:’value’}
check if it’s added: print(‘italy’in europe)-> True
delete: del(europe[‘australia’])

Dictionary of dictionaries:
europe = {‘spain’:{‘cap’:’madrid’,’pop’:46.77}, ‘france’:
{‘cap’:’paris’,’pop’:66.03}}

Create sub-dict data: (1) data = {‘capital’:’rome’, ‘population’:59,85}
(2) europe[‘italy’] = data

Select elements: europe[‘spain’][‘pop’]  46.77

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
lisaholling1 Tilburg University
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
130
Lid sinds
5 jaar
Aantal volgers
91
Documenten
14
Laatst verkocht
4 weken geleden

4,3

14 beoordelingen

5
9
4
2
3
2
2
0
1
1

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen