on the job Flashcards
1
Q
check current working directory
A
import os
os.getcwd()
2
Q
change current working directory
A
import os
os.chdir(“<path>")</path>
3
Q
create path/filename connection
A
os.path.join(path, filename)
4
Q
reading excel
A
pd.read_excel(name, sheet_name = ‘Sheet’)
5
Q
reading excel and importint as all strings
A
pd.read_excel(filename, sheet_name = ‘Sheet’, dtype = str)
6
Q
count nr of rows in dataframe
A
len(df.index)
7
Q
subset a file to some variables
A
df_subset = df[[“col1”, “col2”]]
8
Q
rename all columns
A
df.columns = [‘col1’, ‘col2’]
9
Q
showing all rows with empty value in certain column
A
df[df[‘var’].isnull()]
10
Q
write to excel/csv
A
df.to_csv(‘filename.csv’, sep = ‘;’)
df.to_excel(‘filename.xlsx’)