博文

目前显示的是 二月, 2020的博文

slider 行

library(slider) library(lubridate) library(tidyverse) x <- c(1, 2, 3, 4, 5) # .before: How many elements before the current one should be included in the window? # .after: How many elements after the current one should be included in the window? # .complete: Should .f only be evaluated when there is enough data to make a complete window?ff # .step: The number of elements to shift forward between calls to .f. slide_vec(x, mean, .before = 1) slide_vec(x, mean, .after = 1) slide_vec(x, sum, .before = 2) slide_vec(x, sum, .before = 2, .complete = T) index_vec <- as.Date("2019-08-29") + c(0, 1, 5, 6) wday_vec <- as.character(wday(index_vec, label = TRUE)) sales_vec <- c(2, 4, 3, 5) company <- tibble(sales = sales_vec,                   index = index_vec,                   wday = wday_vec) # Over columns: map(company, ~ .x) # Over rows: # slide(company, ~ .x) big_index_vec <- c(as.Date("2019-08-30") + 0:4,                

代理测试

http代理 curl -x 127.0.0.1:10809 https://google.com sock5代理 curl --socks5 127.0.0.1:10808 https://google.com/

pip upgrade all

import pkg_resources from subprocess import call packages = [dist.project_name for dist in pkg_resources.working_set] call("pip install --upgrade " + ' '.join(packages), shell=True) ----- pip install -U $(pip freeze | awk '{split($0, a, "=="); print a[1]}') ---- pip freeze > pip_frozen.txt pip install -r pip_frozen.txt --upgrade

Python pip配置国内源

1、 Linux平台安装方式: (1)创建 pip.conf 文件  首先运行以下命令 cd ~/.pip # 运行此命令切换目录  如果提示目录不存在,自行创建一个(如果目录存在,可跳过此步),如下: mkdir ~/.pip cd ~/.pip  在 .pip 目录下创建一个 pip.conf 文件,如下: touch pip.conf (2)编辑 pip.conf 文件  首先打开文件,命令如下: sudo vi ~/.pip/pip.conf  接着,写入以下内容: [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn # trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任 然后保存退出即可。  2、Window平台安装方式: (1)新建  pip  配置文件夹,直接在user用户目录中创建一个名为 pip  的文件夹( 即 %HOMEPATH%\pip ),如下图所示: (2)接着在 pip 文件夹中创建一个名为 pip 的文本文件(后缀名由" .txt "改为 " .ini "),格式如下所示:  文件内容如下: [global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple [install] trusted-host = https://pypi.tuna.tsinghua.edu.cn # trusted-host 此参数是为了避免麻烦,否则使用的时候可能会提示不受信任 修改完成后保存,启动 cmd ,使用 " pip install xxx "( xxx 为你要下载的包名),即可默认使用国内源下载。

across and case_when

library(tidyverse) #across将一个或多个函数应用在选择列上 iris %>% as_tibble() %>%   mutate(mean=(rowMeans(across(starts_with('Sepal'))))) iris %>%   group_by(Species) %>%   summarise(across(starts_with('Sepal'),mean)) iris %>%   group_by(Species) %>%   summarise(across(starts_with('Sepal'),~mean(.x,na.rm = T))) #避免了写多个列的麻烦 iris %>%   group_by(Species) %>%   summarise(mean=mean(Sepal.Length)) starwars %>%   select(name:mass, gender, species) %>%   mutate(     type = case_when(       height > 200 | mass > 200 ~ "large",       species == "Droid"        ~ "robot",       TRUE                      ~ "other"     )   )

pip不能安装、升级、卸载软件问题

Cannot uninstall ‘nibabel’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. 问题解析: 旧版本依赖多,不能清晰的删除,此时应该忽略旧版本升级,即如下 解决办法:sudo pip install nibabel --ignore-installed nibabel 下载安装 https://www.lfd.uci.edu/~gohlke/pythonlibs/ conda update --all --force-reinstall conda update conda --force-reinstall Windows10中,用户目录下.condarc 配置为: channels: – defaults # Show channel URLs when displaying what is going to be downloaded and # in ‘conda list’. The default is False. show_channel_urls: True allow_other_channels: True proxy_servers: http: socks5:// 127.0 . 0.1 : 1080 https: socks5:// 127.0 . 0.1 : 1080 ssl_verify: False

ubuntu install qqff

wget -O- https://deepin-wine.i-m.dev/setup.sh | sh sudo apt install deepin.com.qq.im sudo apt install deepin

R 重采样

library(hyfo) library(lubridate) # Daily to monthly 降采样 TS <- data.frame(Date = seq(ymd('1999-01-01'), length = 365, by = '1 day'),                  num=runif(365, 3, 10)) TS_new <- resample(TS, method = 'day2mon') # Monthly to daily 升采样 TS <- data.frame(Date = seq(ymd('1999-01-01'), length = 12, by = '1 month'),                  num=runif(12, 3, 10)) TS_new <- resample(TS, method = 'mon2day') library(dplyr) library(lubridate) set.seed(2017) options(digits=4) expenses <- tibble(   date=seq(ymd("2019-01-01"), ymd("2020-12-31"), by=1),   amount=rgamma(length(date), shape = 2, scale = 20)) expenses %>% group_by(month=floor_date(date, "month")) %>%   summarize(amount=sum(amount)) expenses %>% group_by(month=floor_date(date, "3month")) %>%   summarize(amount=sum(amount)) expenses %>% group_by(month=floor_date(date, "year")) %>%   summarize(amount=sum(amount)

R#将1列拆分成多列

library(tidyverse) library(stringr) df <- read.csv('~/PycharmProjects/datascience/data/911.csv') #将1列拆分成多列 df3 <- df %>% separate(title,c('a','b'),sep=': ') table(df3$a) df <- read.csv('~/PycharmProjects/datascience/data/911.csv',header = T) df2 <- as.tibble(do.call(rbind, str_split(df$title, ': '))) table(df2$V1)

python on Rstudio.py

Sys.setenv(RETICULATE_PYTHON = "/usr/bin/python3.6") # reticulate::py_config() import request import matplotlib import numpy as np import pandas as pd