This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Turns a dictionary into a class | |
# type variable name such as t4. and wait for the class attributes to appear in editor using Kite or other language processors | |
class Dict2Class(object): | |
def __init__(self, my_dict): | |
for key in my_dict: | |
key2=key.replace(" ","_") #key2 for valid names without spaces for object attributes | |
key2=key2.replace(":","_") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create an 8 row by 2 columns dataframe with column labels | |
df=pd.DataFrame(np.reshape(np.zeros(16),(8,2)),columns=['x','y']) # create an 8 row by 2 columns df | |
c=df23.columns.to_list() | |
c[0] | |
df.iloc[0:,0:2] # rows 0 through end of column 0 and 1 | |
#---------- | |
df.drop(df.columns[[0, 4, 2]], axis = 1, inplace = True) #drop columns using column index | |
#---------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
import re | |
#str1, n = re.subn('[0-9]', 'X',str1) | |
def ntuples(df): | |
list_of_names = df.columns.values | |
print(list_of_names[0:2]) | |
list_of_names_dict = {x:x for x in list_of_names} | |
Varnames = namedtuple('Varnames', list_of_names) |
NewerOlder