on the job Flashcards

1
Q

check current working directory

A

import os
os.getcwd()

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

change current working directory

A

import os
os.chdir(“<path>")</path>

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

create path/filename connection

A

os.path.join(path, filename)

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

reading excel

A

pd.read_excel(name, sheet_name = ‘Sheet’)

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

reading excel and importint as all strings

A

pd.read_excel(filename, sheet_name = ‘Sheet’, dtype = str)

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

count nr of rows in dataframe

A

len(df.index)

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

subset a file to some variables

A

df_subset = df[[“col1”, “col2”]]

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

rename all columns

A

df.columns = [‘col1’, ‘col2’]

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

showing all rows with empty value in certain column

A

df[df[‘var’].isnull()]

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

write to excel/csv

A

df.to_csv(‘filename.csv’, sep = ‘;’)
df.to_excel(‘filename.xlsx’)

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