工作备忘

1. ParserError: Error tokenizing data. C error: EOF inside string starting at row ……

解决方法:

import csv

quoting=csv.QUOTE_NONE

error_bad_lines=False

sep=r'\s{1,}' # 解决空格分列

2.Python处理string日期:yyyymmdd 想变成 yyyy--mm--dd

x['origin_dayno'] = pd.to_datetime(x['dayno'], format='%Y%m%d').dt.strftime('%Y-%m-%d')

x['change_dayno'] = pd.to_datetime(x['change_time'], format='%Y%m%d').dt.strftime('%Y-%m-%d')

3.Python 分列时间

df['year'] = df['dayno'].map(lambda x:x.split('-')[0])

df['month'] = df['dayno'].map(lambda x:x.split('-')[1])

4. SQL 计算日期相差和月份相差

#日期

datediff('2021-06-01',from_unixtime(unix_timestamp(cast(first(t1.dayno) as string),'yyyymmdd'),'yyyy-mm-dd')) 

datediff(concat(substr(${YYYYMMDD},1,4),'-',substr(${YYYYMMDD},5,2),'-',substr(${YYYYMMDD},7,2)),concat(substr(t1.date_time,1,4),'-',substr(t1.date_time,5,2),'-',substr(t1.date_time,7,2)))as changed_duration_day,

#月份

 cast(months_between('2021-06-01',from_unixtime(unix_timestamp(cast(first(t1.dayno) as string),'yyyymmdd'),'yyyy-mm-dd')) as int) 

 cast(months_between((from_unixtime(unix_timestamp(cast(${YYYYMMDD} as string),'yyyymmdd'),'yyyy-mm-dd')),concat(substr(t1.date_time,1,4),'-',substr(t1.date_time,5,2),'-',substr(t1.date_time,7,2))) as int)as changed_duration_month,

5.hive create table

create table if not exists xxxx(新表名)as  select xxx

6. 工程化部署

insert overwrite table 表名 partition (dayno=${YYYYMMDD}) #分区表

7. substr函数格式   (俗称:字符截取函数)

格式1: substr(string string, int a, int b);

格式2:substr(string string, int a) ;

解析:

格式1:

1、string 需要截取的字符串

2、a 截取字符串的开始位置(注:当a等于0或1时,都是从第一位开始截取)

3、b 要截取的字符串的长度

格式2:

1、string 需要截取的字符串

2、a 可以理解为从第a个字符开始截取后面所有的字符串。

8. SQL 求Quantile

select approx_percentile(prediction,0.95,99999)

9. count

count(*)=count(1)>count(id)>count(字段)

你可能感兴趣的:(工作备忘)