forked from JostTim/pGenUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexterns.py
More file actions
42 lines (34 loc) · 1.13 KB
/
externs.py
File metadata and controls
42 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 23 14:49:52 2021
@author: Timothe
"""
try :
import pandas as pd
except :
pass
def empty_df(columns, dtypes=[], index=None):
"""
Creates an empty dataframe with the columns and data types as specified.
*Previously named df_empty*
Args:
columns (list): list of columns names (list of str) .
dtypes (list, optional): list of data types. Can be numpy built in data types, pandas, or numpy.
index (list, optional): Index name. Defaults to None. (If None : auto integer index corresponding to row numbers)
Todo:
Add ability to create multi-index with that function
Returns:
pd.DataFrame : The dataframe with the desired columns names and indices.
"""
df = pd.DataFrame(index=index)
if ( type(dtypes) == list or type(dtypes) == tuple) and len(columns)==len(dtypes):
for c,d in zip(columns, dtypes):
df[c] = pd.Series(dtype=d)
else :
if type(dtypes) == type :
d = dtypes
else :
d = float
for c in columns:
df[c] = pd.Series(dtype=d)
return df