我正在使用dc.js渲染数据集的漂亮气泡图.底层dc.js是crossfilter.
我想用服务器上的新数据顺利刷新我的图表.Github上的这个问题清楚地表明可以通过以下方式实现:
dc.redrawAll().我有这个工作,但为了删除所有数据,您首先必须清除所有过滤器(因为crossfilter.remove只删除与当前过滤器匹配的记录).
我想"记住"之前我的数据是如何过滤的,所以一旦我替换了所有数据,我就可以重新构建过滤器.我愿意深入了解crossfilter代码的内容,但任何指针都会有所帮助.
另外:如果有人知道基于唯一键更新crossfilter数据的方法,那就是金尘!
我pd.DataFrame喜欢这个:
ColumnName
1
1
2
3
1
2
3
1
2
2
Run Code Online (Sandbox Code Playgroud)
我可以用它来绘制它 df['ColumnName'].plot(style='o')
如何为列中的不同值定义不同的颜色(例如,红色表示值1,绿色表示2,橙色表示3).我知道这与它有关colormap,但我如何使用它?
解决方案是DataFrame使用每个值的列构造一个new .但是这些值是排序的,我希望这个序列只是以不同的颜色着色.
我有一个 MS SQL 数据库和一个 postgres 数据库。任何一种解决方案都可以,因为我可以翻译它。
我们有一个customer_phone表格,其中相关的列是:
id, customer_id, phone, is_bad
Run Code Online (Sandbox Code Playgroud)
我需要做的是customer_id从这张表中选择所有只有is_bad = true. 因此,如果您有 1 个好电话号码和 1 个坏电话号码,则不应出现。
出于某种原因,我正在努力寻找一种简单的方法来做到这一点,我觉得它应该看起来很简单。
这是一个开始,至少可以让我对所有客户的好坏数字进行计数,但我想知道是否有一种方法不需要使用子查询和in's?
select customer_id, is_bad, count(customer_id)
from customer_phone cp
group by customer_id, is_bad
order by customer_id desc
Run Code Online (Sandbox Code Playgroud) 根据文档,您可以忽略这样的警告:
@pytest.mark.filterwarnings("ignore:api v1")
def test_foo():
Run Code Online (Sandbox Code Playgroud)
这使:
但是似乎没有关于这种迷你语言的任何文档(它甚至是迷你语言吗?)
比赛是如何进行的?
我问这个是因为以下测试不会忽略DeprecationWarning通过导入引发的boto3:
@pytest.mark.filterwarnings("ignore:DeprecationWarning")
def test_ignore_warnings():
import boto3
Run Code Online (Sandbox Code Playgroud)
pytest 输出:
============================================================================================================================== warnings summary ===============================================================================================================================
/home/rob/dev/time-series/.venv/lib/python3.7/site-packages/botocore/awsrequest.py:624
/home/rob/dev/time-series/.venv/lib/python3.7/site-packages/botocore/awsrequest.py:624: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
class HeadersDict(collections.MutableMapping):
-- Docs: https://docs.pytest.org/en/latest/warnings.html
==================================================================================================================== 1 passed, 1 warnings in 0.36 seconds =====================================================================================================================
Run Code Online (Sandbox Code Playgroud) 我有一个Cython名为foo.pyx包含以下功能的文件:
def add_one(int n):
cdef int m = n + 1
return m
cdef int c_add_one(int n):
return n + 1
Run Code Online (Sandbox Code Playgroud)
我使用构建此pyx文件cython -a foo.pyx,然后可以执行:
>>> import foo
>>> foo.add_one(5)
6
>>> foo.c_add_one(5)
AttributeError: 'module' object has no attribute 'c_add_one'
Run Code Online (Sandbox Code Playgroud)
所以看起来我无法c_add_one从python 调用.使用声明函数有什么好处cdef?
(请注意,这个 SO 问题看起来相似但不同。)
我有一个 MultiIndexed,DataFrame其中包含代表年度数据的列:
>>> x = pd.DataFrame({
'country': {0: 4.0, 1: 8.0, 2: 12.0},
'series': {0: 553.0, 1: 553.0, 2: 553.0},
'2000': {0: '1100', 1: '28', 2: '120'},
'2005': {0: '730', 1: '24', 2: '100'}
}).set_index(['country', 'series'])
>>> x
2000 2005
country series
4 553 1100 730
8 553 28 24
12 553 120 100
Run Code Online (Sandbox Code Playgroud)
当我堆叠年份时,新的索引级别没有名称:
>>> x.stack()
country series
4 553 2000 1100
2005 730
8 553 2000 28
2005 24
12 553 …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的MultiIndexed DataFrame:
In [2]: ix = pd.MultiIndex.from_product([[1, 2, 3], ['foo', 'bar'], ['baz', 'can']], names=['a', 'b', 'c'])
In [3]: data = np.arange(len(ix))
In [4]: df = pd.DataFrame(data, index=ix, columns=['hi'])
In [43]: df = df[~df.hi.isin([2, 3])]
In [44]: df
Out[44]:
hi
a b c
1 foo baz 0
can 1
2 foo baz 4
can 5
bar baz 6
can 7
3 foo baz 8
can 9
bar baz 10
can 11
Run Code Online (Sandbox Code Playgroud)
我想知道DataFrame中哪些级别a和b出现的对:
[(1, 'foo'), (2, 'foo'), (2, …Run Code Online (Sandbox Code Playgroud) 我有像单元格的条件格式
=COUNTIF(A3:H2663;R5)
Run Code Online (Sandbox Code Playgroud)
如果输入的值 R5其他地方找到,则该框将变为红色.
但是,有时它不是完全匹配,然后它不能识别它.这可能是因为输入数字末尾的额外数字.
所以我的问题是:如果单元格中A3:H2663只包含值R5,并且不是完全匹配,我可以更改公式以进行匹配吗?
我经常与大型图书馆(例如pandas或matplotlib)合作。
这意味着异常通常会产生较长的堆栈跟踪。
由于该错误很少出现在库中,而错误经常出现在我自己的代码中,因此在大多数情况下,我不需要查看库的详细信息。
几个常见的例子:
>>> import pandas as pd
>>> df = pd.DataFrame(dict(a=[1,2,3]))
>>> df['b'] # Hint: there _is_ no 'b'
Run Code Online (Sandbox Code Playgroud)
在这里,我尝试访问未知密钥。这个简单的错误产生一个包含28行的stacktrace:
Traceback (most recent call last):
File "an_arbitrary_python\lib\site-packages\pandas\core\indexes\base.py", line 2393, in get_loc
return self._engine.get_loc(key)
File "pandas\_libs\index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5239)
File "pandas\_libs\index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas\_libs\index.c:5085)
File "pandas\_libs\hashtable_class_helper.pxi", line 1207, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20405)
File "pandas\_libs\hashtable_class_helper.pxi", line 1215, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas\_libs\hashtable.c:20359)
KeyError: 'b'
During handling of the above exception, another exception occurred:
Traceback …Run Code Online (Sandbox Code Playgroud) 当浏览器点击“webpackified”文件中的以下行时,我收到此错误app.js:
/******/ (function(modules) { // webpackBootstrap
/******/ function hotDisposeChunk(chunkId) {
/******/ delete installedChunks[chunkId];
/******/ }
/******/ var parentHotUpdateCallback = this["webpackHotUpdate"];
Run Code Online (Sandbox Code Playgroud)
在此片段的最后一行中,this未定义。
尽管出现此错误,该应用程序似乎运行得很好。
我不确定webpack.config.js文件的哪些部分最相关,但以下是一些可能相关的片段:
const HotModuleReplcement = new webpack.HotModuleReplacementPlugin();
...
module.exports = {
...
devServer: {
historyApiFallback: true,
hot: true,
inline: true,
port: 8000,
open: true,
proxy: [{
context: ['/assets', '/api'],
target: 'http://localhost:4000',
secure: false
}]
},
plugins: [HotModuleReplcement, HtmlWebpack]
};
Run Code Online (Sandbox Code Playgroud)
知道这里发生了什么吗?
python ×6
pandas ×3
javascript ×2
colors ×1
count ×1
crossfilter ×1
cython ×1
dataframe ×1
dc.js ×1
excel ×1
formula ×1
match ×1
plot ×1
postgresql ×1
pytest ×1
python-3.x ×1
sql ×1
stack-trace ×1
webpack ×1