#中文月份和星期字符串ch_month_names =["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月", ] ch_week_names= ["星期一","星期二","星期三","星期四","星期五","星期六","星期日"]defchinese_calendar(year, month): cal=calendar.month(year...
week_list[df["出生日期"][0].weekday()] df["出生星期几"]=df["出生日期"].apply(lambda x:week_list[x.weekday()]) 5根据出生日期计算每个人出生的前一个月的最后一天的日期 def lastday(year,month): weekday,monthcountdays = calendar.monthrange(year,month) lastday = datetime.date(year,mont...
import re # 正则表达式库import jieba # 结巴分词 import jieba.posseg # 词性获取 import collections # 词频统计库 import numpy # numpy数据处理库seg_list_exact = jieba.cut(string_data, cut_all=False, HMM=True) # 精确模式分词+HMM jieba.load_userdict("词典.txt") # 批量添加词典,utf-8编码 wi...
内置提供的类型:int、str、float,typing模块提供的类型:Dict、List、Tuble... typing使用方括号Dict[str, int]而不是圆括号Dict(str, int) fromtypingimportList,Tuple,Dict names:List[str]=["li","tom"]version:Tuple[int,int,int]=(6,6,6)operations:Dict[str,bool]={'sad':False,'happy':True} Li...
Unit Root Test Thenullhypothesisofthe Augmented Dickey-Fuller is that there is a unit root,withthe alternative that there is no unit root.That is to say the bigger the p-value the more reason we assert that there is a unit root''' def testStationarity(ts): dftest = adfuller(ts) # ...
get_file_list_cur(types=0): filelist = [] fileNames = glob.glob(FLASH_HOME_PATH + r"/*.*") try: for fileName in fileNames: name = os.path.basename(fileName) filelist.append(name) except Exception as reason: logging.error("Failed to get file list! reason = {} ".format(reason...
Else, return an alphabetized list of names comprising (some of) the attributesof the given object, and of attributes reachable from it.If the object supplies a method named __dir__, it will be used; otherwisethe default dir() logic is used and returns:...
from datetime import datetime from typing import List, Optional from pydantic import BaseModel class User(BaseModel): id: int name = 'John Doe' signup_ts: Optional[datetime] = None friends: List[int] = [] external_data = { 'id': '123', 'signup_ts': '2019-06-...
# list of ints or names. e.g. If [1, 2, 3] -> try parsing columns 1, 2, 3 each as a separate date column. # list of lists. e.g. If [[1, 3]] -> combine columns 1 and 3 and parse as a single date column. # dict, e.g. {'foo' : [1, 3]} -> parse columns ...
{} movie_ids = list(df[0].values) movie_name = list(df[1].values) for k,v in zip(movie_ids,movie_name): movie_dict[k] = v return movie_dict # Function to create training validation and test data def train_val(df,val_frac=None): X,y = df[['userID','movieID']].values,...