python Flashcards

(90 cards)

1
Q

Find the last char in str

A

str[-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Find the second to last char in str

A

str[-2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Find the whole string apart for the last two chars

A

str[ :-2]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Find the whole string apart for the first two chars

A

str[ 2: ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

iterate over str

A

for i in range(len(str)):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Find the end of [ ] of numbers then check ==9

A

end = len(nums)
for i in range (end):
if nums [ i ] == 9:
return True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Look for one number in an array of numbers

A

for number in nums:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

a function with if and then else if and else to find your fashion level.

A
def date_fashion(you, date):
    if you < 3 or date < 3:
        return 0
    elif you >= 8 or date >=8 :
        return 2
    else:
        return 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Find the position of w

A

astring = “Hello world!”

print(astring.index(‘w’))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Put a string in reverse

A

print(astring[::-1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

String to upper then lower

A

print(astring.upper())

print(astring.lower())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The environment

A

consists of Python standard libraries and pre-installed packages

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does a package always have

A

__init__.py

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What error do you get if the package is missing in your system?

A

ModuleNotFoundError

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

List

A

[1,2,3,4]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

List properties

A
  1. They are ordered.
  2. They can contain any objects.
  3. Their size can be varied.
  4. They are nestable that is
    they can contain other lists
    as elements.
  5. Their elements can be accessed
    by index.
  6. They are mutable that is
    you can perform various functions
    on it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

The keys of the dictionary are

A

immutable , unordered and Unique

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Tuples

A

immutable list.
heterogeneous sequence of elements,
impossible to append, edit or remove any individual elements within a tuple.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

while Panel data

A

are observations over time, of the same characteristic for multiple entities

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Using the map function

A

anw = list(map(lambda x,y: x+y , list_1, list_3 ))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

An array ?

A

Array is it a list of related data types, [ [] [] [] ], used to multidimensional array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Numpy arrays advantage ?

A

Numpy arrays are helpful due to vectorisation and the ability to broadcast one row against another row, they can only work Arrays.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

one dimensional arrays’ are know as ?

A

‘vectors’. ‘Scalars

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

NumPy array

A

np.array( [ [] [] [] ] )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
print (A2[2:4:1,2:7:2]) what will happen
Brings row 2 & every digit | and brings columb 2, 6 every other digit
26
Make a few lists of the same type in np
V2 = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
27
to make up a 50 item array and then reshape it to 10 rows by 5 columns ?
np.linspace(1,50).reshape(10,5)
28
Example of a tuple ?
Tuples have no append or extend method. Elements cannot be removed from a tuple. (2,3,4,5,6)
29
Change a row to a column
B = np.array([1, 2, 3]) output = B[ : , np.newaxis ] print (output)
30
Used to delaet column
DataFrame.drop()
31
Which of the following functions is used for indexing within a dataframe?
DataFrame.iloc()
32
What does the series constructor look like
pd.Series([10, 20, 30, 40, 50, 60])
33
how to times Series data with tan
My_Series = (S3+S4).apply(np.tan)
34
DataFrame drop index rows
shop = shop.drop(shop.index[0 : 247]) | shop
35
out of dataframe slice first 3 lines and first 3 columns
df.iloc[:2,:3]
36
group items ?
df.groupby( ['Market', 'Sector'] ).groups
37
Loop
for i in range(len(shop)): if shop.iloc[i]["Close"] > 1420 : print( shop.iloc[ i ] [ "Close" ] )
38
Work out percent change on row and column
shop.iloc[ 1 : 4 , 3 : 4 ].pct_change()
39
To create event driven trading
schedule strategy stream data place orders
40
How do you change from the ‘base’ environment to an environment named ‘quantra_py’?
. conda activate quantra_py
41
VWAP
Volume weighted average price
42
FInd help in Pythong
Help( ) or ? after item
43
print statement
print ( " {0:1s} " has {1 : .1 f} outstanding " . format( name, number ) )
44
magic commands
%lmagic , %magic , %who
45
add list item
list . append ("jonathon") | list . insert (0,"jon" )
46
ballian check in list
print ( "jon" in family_list) | True
47
Index using np
np.argmax(list)
48
Looking for items in a list > 200
np.where( (list >200) & (list <300) )
49
What is a set
set = {'a','a','u'}
50
a = a + 1`
a += 1
51
how to get the current working dir
import os | os.getcwd()
52
FInd if about data frame
df.info() df.describe()
53
read in csv set index
data3 = pd.read_csv( " shop.csv", index_col="Date", parse_dates=True, dayfirst=True)
54
make a data frame
close_open = df [ [ 'Close', 'Open'] ]
55
to delete column
del df['New']
56
sum a whole column
df['Volume'].sum()
57
df open <1250
df [ ( df['Open'] < 1250 ) ]
58
selecting rows
df.iloc[ [ 4, 8, 20] ]
59
Selecting two rows and two columns
df.iloc[[4, 5], [0,3]]
60
closing change for day before
df['Close_to_Close'] = 100 * df['Close'] . pct_change()
61
Creating a new column called 'Previous_Close' by using the shift operator on Close column.
df['Previous_Close'] = df[ 'Close' ].shift(1) | df.head()
62
Creating a new column called 'MA' containing 5 day Moving Average of Close prices.
df['MA_5'] = df[ 'Close' ] . rolling (window=n).mean()
63
finding missing values
df.isnull().sum()
64
drop nana rows
df.dropna(axis=0).head()
65
fill forward
df.fillna( method='ffill' ).head()
66
function to find range then populate
``` def daily_range(x): return x['Close']-x['Open'] df['daily_range'] = df.apply ( daily_range, axis=1 ) ```
67
supervised learning example
classification or regression learning
68
unsupervised learning
clustering
69
a set order doesn't matter
{ , , ,}
70
what is the difference in continue and break
continue is more lie skip | break
71
Mak 1 col all 0
df.iloc { 10:50 , 6 } = 0
72
find out directories in package
dir( read_csv )
73
show all variables in memory
%%whos
74
work out average over 5 days
df{new_col} = df[ 'close" ].rolling(5).mean()
75
Sum of all null values
df . isnull() . sum()
76
Change to datatime
df = pd.to_datetime( df.index )
77
logical condition
con = (df1_msft["p"] > 0) | df1_msft.loc[ con ]
78
Make the first col an index
index_col= [ 0 ] , parse_dates=True
79
Help on function
yf . download?
80
today's date
today = datetime.date.today()
81
to get all instance attributes
__dict__
82
family tree
__mro__
83
pass attributes and methods to child class
cls pass
84
Inherit methods from parents
Use supper | parent1.__init__(self,age) / parent2.__init__(self,age)
85
Find to days date
pd.datetime.now()
86
Date in the past
pd.Timedelta(days=30)
87
make a df
list1 =[ 1,2,3,4,5,6,7] | test_df = pd.DataFrame( { "name" : list1 } )
88
add to list
stock_list.extend( )
89
How to plot scatter
DataFrame.plot.scatter(test_df.plot.scatter( x="name",y="name",c="red", figsize=(12,5) ) )
90
work out log returns for stock
stock_df[stock] = np.log( ['Close'] / stock_df['Open'] )