我注意到使用基本操作系统Alpine与CentOS或Debian在Docker容器中安装Pandas和Numpy(它的依赖关系)需要更长的时间.我在下面创建了一个小测试来演示时差.除了Alpine更新和下载构建依赖项以安装Pandas和Numpy的几秒钟之外,为什么setup.py需要比Debian安装多70倍的时间?
有没有办法加速使用Alpine作为基本图像的安装,或者是否有另一个与Alpine相当的基本图像,最好用于像Pandas和Numpy这样的软件包?
Dockerfile.debian
FROM python:3.6.4-slim-jessie
RUN pip install pandas
Run Code Online (Sandbox Code Playgroud)
使用Pandas&Numpy构建Debian映像:
[PandasDockerTest] time docker build -t debian-pandas -f Dockerfile.debian . --no-cache
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM python:3.6.4-slim-jessie
---> 43431c5410f3
Step 2/2 : RUN pip install pandas
---> Running in 2e4c030f8051
Collecting pandas
Downloading pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl (26.2MB)
Collecting numpy>=1.9.0 (from pandas)
Downloading numpy-1.14.1-cp36-cp36m-manylinux1_x86_64.whl (12.2MB)
Collecting pytz>=2011k (from pandas)
Downloading pytz-2018.3-py2.py3-none-any.whl (509kB)
Collecting python-dateutil>=2 (from pandas)
Downloading python_dateutil-2.6.1-py2.py3-none-any.whl (194kB)
Collecting six>=1.5 (from python-dateutil>=2->pandas)
Downloading six-1.11.0-py2.py3-none-any.whl
Installing collected packages: …Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制一条直接穿过我所有数据点的平滑线,并且具有基于另一个变量的渐变.理论上多项式插值可以完成工作,但我不确定如何使用ggplot.这是我到目前为止所提出的:
数据:
dayofweek hour impressions conversions cvr
1 0 3997982 352.0 8.80e-05
1 1 3182678 321.2 1.01e-04
1 2 2921004 248.6 8.51e-05
1 3 1708627 115.6 6.77e-05
1 4 1225059 98.4 8.03e-05
1 5 1211708 62.0 5.12e-05
1 6 1653280 150.0 9.07e-05
1 7 2511577 309.4 1.23e-04
1 8 3801969 397.8 1.05e-04
1 9 5144399 573.0 1.11e-04
1 10 5770269 675.6 1.17e-04
1 11 6936943 869.8 1.25e-04
1 12 7953053 996.4 1.25e-04
1 13 8711737 1117.8 1.28e-04
1 14 9114872 …Run Code Online (Sandbox Code Playgroud) 我正在尝试用空列表[]替换数据中的一些NaN值.但是,列表表示为str,不允许我正确应用len()函数.无论如何用大熊猫中的实际空列表替换NaN值?
In [28]: d = pd.DataFrame({'x' : [[1,2,3], [1,2], np.NaN, np.NaN], 'y' : [1,2,3,4]})
In [29]: d
Out[29]:
x y
0 [1, 2, 3] 1
1 [1, 2] 2
2 NaN 3
3 NaN 4
In [32]: d.x.replace(np.NaN, '[]', inplace=True)
In [33]: d
Out[33]:
x y
0 [1, 2, 3] 1
1 [1, 2] 2
2 [] 3
3 [] 4
In [34]: d.x.apply(len)
Out[34]:
0 3
1 2
2 2
3 2
Name: x, dtype: int64
Run Code Online (Sandbox Code Playgroud) 似乎不可能使用 RegexRoute 用下划线替换主题名称中的所有点,因为 RegexRouter 调用replaceFirstnot replaceAll。有没有解决的办法?我的一个想法是通过变换进行多次传递:
{
"connector.class": "io.confluent.connect.s3.S3SinkConnector",
"tasks.max": "10",
"topics": "foo.bar.baz,some.topic",
"s3.region": "us-east-1",
"s3.bucket.name": "bucket",
"s3.part.size": "5242880",
"s3.compression.type": "gzip",
"timezone": "UTC",
"rotate.schedule.interval.ms": "900000",
"flush.size": "1000000",
"storage.class": "io.confluent.connect.s3.storage.S3Storage",
"format.class": "io.confluent.connect.s3.format.bytearray.ByteArrayFormat",
"partitioner.class": "io.confluent.connect.storage.partitioner.TimeBasedPartitioner",
"path.format": "'year'=YYYY/'month'=MM/'day'=dd/'hour'=HH",
"timestamp.extractor": "RecordField",
"timestamp.field": "time",
"schema.compatibility": "NONE",
"name": "s3-sink",
"transforms":"replaceFirstDot,replaceSecondDot",
"transforms.replaceFirstDot.type": "org.apache.kafka.connect.transforms.RegexRouter",
"transforms.replaceFirstDot.regex": "\\.",
"transforms.replaceFirstDot.replacement": "_",
"transforms.replaceSecondDot.type": "org.apache.kafka.connect.transforms.RegexRouter",
"transforms.replaceSecondDot.regex": "\\.",
"transforms.replaceSecondDot.replacement": "_"
}
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法来包含自定义分区器或转换/路由器?
我最近一直在使用Airflow,并且找到一个非常常见的模式是循环一些集合以创建多个任务.非常类似于github中示例dags文件夹中的example_python_operator.py dag.
我的问题与动态构建循环迭代的集合有关.假设您要为存储在数据库中的每个未知客户端创建一个任务,并且您计划将它们作为填充列表的方法进行查询.像这样的东西:
first_task = PythonOperator(
task_id='some_upstream_task',
provide_context=True,
python_callable=some_upstream_task,
dag=dag)
clients = my_database_query()
for client in clients:
task = PythonOperator(
task_id='client_' + str(client),
python_callable=some_function,
dag=dag)
task.set_upstream(first_task)
Run Code Online (Sandbox Code Playgroud)
从我所看到的情况来看,这意味着即使您的dag每周只运行一次,您的数据库也会每30秒为这些客户端进行一次轮询.即使您从迭代器设置了一个上游运算符并通过xcoms返回客户端,并且每隔30秒替换my_database_query()一次xcom_pull()仍然轮询的xcoms.这对我来说似乎很浪费,所以我想知道这种类型的dag是否有更好的模式?
我一直在四处寻找是否有可能在 Google Cloud Storage 存储桶中托管静态 React 应用程序并使用 Google Cloud CDN 和单个 Google Cloud Load Balancer 将缓存未命中路由到存储桶,管理证书,并将来自 React 应用程序的内部请求路由到 GKE 中托管的 API?
是否有可能实现这种架构,或者是否有另一种推荐的方法?
reactjs google-cloud-platform google-cloud-cdn google-cloud-load-balancer
遇到如何虚拟编码以下数据集的问题.
示例数据,比方说dataframe = mydata:
ID | NAMES |
-- | -------------- |
1 | 4444, 333, 456 |
2 | 333 |
3 | 456, 765 |
Run Code Online (Sandbox Code Playgroud)
我想只将NAMES中的唯一变量作为列变量和代码转换为每行是否具有该变量,即1或0
期望的输出:
ID | NAMES | 4444 | 333 | 456 | 765 |
-- | -------------- |------|-----|-----|-----|
1 | 4444, 333, 456 | 1 | 1 | 1 | 0 |
2 | 333 | 0 | 1 | 0 | 0 |
3 | 456, 765 | 0 | 0 | …Run Code Online (Sandbox Code Playgroud) 我想知道将celery与Django脱钩以便对这两个部分进行docker化并使用docker swarm服务的最佳方法是什么?通常,人们使用引用那里Django应用程序的命令来启动他们的celery worker和celery beat:
celery worker -A my_app
celery beat -A my_app
Run Code Online (Sandbox Code Playgroud)
从这个我相信celery从设置文件和一个celery.py文件中获取配置信息,该文件很容易转移到微服务中。我不完全了解这些任务将如何利用Django ORM?还是不是真的应该设计微服务的口头禅和Celery来对完成任务所需的数据进行Django REST Framework API的GET / POST调用?
我在R中的stl()时间序列分解函数有问题告诉我,当它实际上是我的ts对象不是单变量的吗?
tsData <- ts(data = dummyData, start = c(2012,1), end = c(2014,12), frequency = 12)
> tsData
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2012 22 26 34 33 40 39 39 45 50 58 64 78
2013 51 60 80 80 93 100 96 108 111 119 140 164
2014 103 112 154 135 156 170 146 156 166 176 193 204
> class(tsData)
[1] "ts"
> stl(tsData, s.window = "periodic")
Error in stl(tsData, …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过自制软件安装gdal所以我可以开始使用topojson,但我一直收到这个错误,我不知道如何解决它?
k-6177:Cellar k$ brew install gdal
==> Installing dependencies for gdal: libpng, giflib, libtiff, lzlib, proj, libgeotiff, geos, sqlite, freexl, libxml2, json-c, liblwgeom, libspatialite
Error: Cannot link libpng
Another version is already linked: /usr/local/Cellar/libpng/1.6.16
Run Code Online (Sandbox Code Playgroud)