我正在玩Python中的随机库来模拟我工作的项目,我发现自己处于一个非常奇怪的位置.
假设我们在Python中有以下代码:
from random import randint
import seaborn as sns
a = []
for i in range(1000000):
a.append(randint(1,150))
sns.distplot(a)
Run Code Online (Sandbox Code Playgroud)
该图遵循"离散均匀"分布.
但是,当我将范围从1更改为110时,绘图有几个峰值.
from random import randint
import seaborn as sns
a = []
for i in range(1000000):
a.append(randint(1,110))
sns.distplot(a)
Run Code Online (Sandbox Code Playgroud)
我的印象是,峰值在0,10,20,30,...但我无法解释它.
编辑:问题与提议的问题不一样,因为我的案例中的问题是seaborn库和我可视化数据的方式.
编辑2:根据对答案的建议,我尝试通过更改seaborn库来验证它.相反,使用matplotlib两个图都是相同的
from random import randint
import matplotlib.pyplot as plt
a = []
for i in range(1000000):
a.append(randint(1,110))
plt.hist(a)
Run Code Online (Sandbox Code Playgroud)
我尝试在每行前面设置一个带有行号的代码预先设置框.我更喜欢用CSS做.这就是我所做的
pre {
background: #303030;
color: #f1f1f1;
padding: 10px 16px;
border-radius: 2px;
border-top: 4px solid #00aeef;
-moz-box-shadow: inset 0 0 10px #000;
box-shadow: inset 0 0 10px #000;
}
pre span {
display: block;
line-height: 1.5rem;
}
pre span:before {
counter-increment: line;
content: counter(line);
display: inline-block;
border-right: 1px solid #ddd;
padding: 0 .5em;
margin-right: .5em;
color: #888
}Run Code Online (Sandbox Code Playgroud)
<pre>
<span>lorem ipsum</span>
<span>>> lorem ipsum</span>
<span>lorem ipsum,\ </span>
<span>lorem ipsum.</span>
<span>>> lorem ipsum</span>
<span>lorem ipsum</span>
<span>lorem ipsum</span>
<span>lorem ipsum</span>
</pre>Run Code Online (Sandbox Code Playgroud)
但是,所有行都具有数字1.增量不起作用.这是一个 …
假设我有一个像这样的数据帧
import pandas as pd
df = pd.DataFrame([[1, 2, 1], [1, 3, 2], [4, 6, 3], [4, 3, 4], [5, 4, 5]], columns=['A', 'B', 'C'])
>> df
A B C
0 1 2 1
1 1 3 2
2 4 6 3
3 4 3 4
4 5 4 5
Run Code Online (Sandbox Code Playgroud)
原始表格更复杂,列数和行数更多.
我想获得符合某些标准的第一行.例子:
但是,如果没有任何行满足特定条件,那么我想在我按A(或其他情况由B,C等)对其进行排序后得到第一行
我能够通过迭代数据帧来做到这一点(我知道掷骰子:P).所以,我更喜欢用更加pythonic的方式来解决它.
我创建了一个有角度的网站,其中包含一个"添加"和一个"删除"表单来操作同一页面上的表格上的数据.
当我在本地或使用Chrome Dev Console(禁用缓存)进行测试时,当我添加新项目或删除新项目时,该表格会自动刷新.当我在客户端的生产服务器(IIS服务器)上测试它时,它仅适用于打开的Chrome开发者控制台.否则,他们必须使用CTRL + F5刷新缓存并在页面上显示更改.
这是组件上的代码:
addProduct() {
this._productsService.addProduct(this.addFormProductItem)
.subscribe(v => {
this._productsService.getProducts().subscribe(
products => {this.products = products, this.onChangeTable(this.config)}
);
});
this.addmodalWindow.hide();
return;
}
onChangeTable(config: any, page: any = {
page: this.page,
itemsPerPage: this.itemsPerPage
}): any {
if (config.filtering) {
Object.assign(this.config.filtering, config.filtering);
}
if (config.sorting) {
Object.assign(this.config.sorting, config.sorting);
}
this.ng2TableData = this.products;
this.length = this.ng2TableData.length;
let filteredData = this.changeFilter(this.ng2TableData, this.config);
let sortedData = this.changeSort(filteredData, this.config);
this.rows = page && config.paging ? this.changePage(page, sortedData) : sortedData;
this.length = sortedData.length;
} …Run Code Online (Sandbox Code Playgroud) 假设我有以下列表
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
Run Code Online (Sandbox Code Playgroud)
我想找到某个长度的所有可能的子列表,其中它们不包含一个特定的数字并且不会丢失数字的顺序.
例如,所有可能的长度为6而没有12的子列表是:
[1,2,3,4,5,6]
[2,3,4,5,6,7]
[3,4,5,6,7,8]
[4,5,6,7,8,9]
[5,6,7,8,9,10]
[6,7,8,9,10,11]
[13,14,15,16,17,18]
Run Code Online (Sandbox Code Playgroud)
问题是,我想在一个非常大的列表中进行,我想要最快捷的方式.
用我的方法更新:
oldlist = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]
newlist = []
length = 6
exclude = 12
for i in oldlist:
if length+i>len(oldlist):
break
else:
mylist.append(oldlist[i:(i+length)]
for i in newlist:
if exclude in i:
newlist.remove(i)
Run Code Online (Sandbox Code Playgroud)
我知道这不是最好的方法,这就是为什么我需要一个更好的方法.
我在我的网站上使用Python Flask,并将几个参数传递给Javascript.这是我的代码:
from flask import Flask
from flask import render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html", param1="Hello")
<html>
<head>
</head>
<body>
<p>Hello World</p>
</body>
<script>console.log({{param1}})</script>
</html>
Run Code Online (Sandbox Code Playgroud)
通过这种方式,它可以毫无问题地工作.这个例子是我自己的简化.但是,如果我想将脚本放在外部文件上并像这样调用它:
<html>
<head>
</head>
<body>
<p>Hello World</p>
</body>
<script src="/static/js/myjs.js"></script>
</html>
Run Code Online (Sandbox Code Playgroud)
而myjs.js文件是console.log({{param1}}),然后它不起作用.那么,有没有办法用Python Flask传递外部Javascript文件中的参数?
关注此问题如何在wordpress上使用qtranslate翻译导航菜单的LINKS?我也尝试翻译其他语言的导航菜单.
我做了第一个答案写的所有内容:
function.php'walker' => new CustomLinkModifierWalker()的header.php文件.<!- -:en- ->HOME<!- -:- -><!- -:gr- ->??????<!- -:- ->和url/en|en|/|gr|但是,翻译不起作用.菜单显示导航中的字符串HOME??????和链接/en|en|/|gr|.
我究竟做错了什么?或者还有另一种翻译菜单的方法吗?
在WordPress 4.0.1下
UPDATE
在[:en]HOME[:el]??????没有上述代码的情况下更改名称会使翻译起作用,但我仍然无法使URL工作.
更新2

和navmenu代码:
希腊语:
<ul class="menu" id="nav-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-1091"><a href="/">??????</a></li>
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-1092"><a href="/#our-company">???????</a></li>
</ul>
Run Code Online (Sandbox Code Playgroud)
对于英语:
<ul class="menu" id="nav-menu">
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-1091"><a href="/">HOME</a></li>
<li class="menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-1092"><a …Run Code Online (Sandbox Code Playgroud) 我有一个Pandas数据帧,并尝试在png文件中保存一个图.但是,似乎某些东西不能正常工作.这是我的代码:
import pandas
import matplotlib.pyplot as plt
import seaborn as sns
sns.set(style='ticks')
df = pandas.read_csv("this_is_my_csv_file.csv")
plot = sns.distplot(df[['my_column_to_plot']])
plot.savefig("myfig.png")
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
AttributeError: 'AxesSubplot' object has no attribute 'savefig'
Run Code Online (Sandbox Code Playgroud) 我对 Promises 有点困惑。我在 Ionic + Angular 中有以下提供程序:
@Injectable()
export class StorageProvider {
constructor( public storage:Storage ) {}
save(keyname: string, data: any): Promise<any> {
return this.storage.set(keyname, data);
}
retrieve(keyname: string): Promise<any> {
return this.storage.get(keyname);
}
clear(): Promise<void> {
return this.storage.clear();
}
delete(keyname): Promise<any> {
return this.storage.remove(keyname);
}
isLogged() {
return this.retrieve('user').then( value => { value ? true : false });
}
}
Run Code Online (Sandbox Code Playgroud)
在我的组件之一中:
console.log(this.storage.isLogged());
Run Code Online (Sandbox Code Playgroud)
问题是它返回了promise对象而不是true或false
如果我将组件更改为:
this.storage.isLogged().then(function(data) { console.log(data)});
Run Code Online (Sandbox Code Playgroud)
然后我得到一个输出 undefined
我有一个以下格式的表格
Id StartDate EndDate Type
1 2012-02-18 2012-03-18 1
1 2012-03-17 2012-06-29 1
1 2012-06-27 2012-09-27 1
1 2014-08-23 2014-09-24 3
1 2014-09-23 2014-10-24 3
1 2014-10-23 2014-11-24 3
2 2015-07-04 2015-08-06 1
2 2015-08-04 2015-09-06 1
3 2013-11-01 2013-12-01 0
3 2018-01-09 2018-02-09 0
Run Code Online (Sandbox Code Playgroud)
我在这里找到了类似的问题,但没有找到可以帮助我解决问题的问题。我想合并具有相同行Id,Type和重叠的日期时间。
上表的结果应为
Id StartDate EndDate Type
1 2012-02-18 2012-09-27 1
1 2014-08-23 2014-11-24 3
2 2015-07-04 2015-09-06 1
3 2013-11-01 2013-12-01 0
3 2018-01-09 2018-02-09 0
Run Code Online (Sandbox Code Playgroud)
在另一台服务器上,我能够做到以下限制和以下查询:
Type列,而是在Id …python ×5
angular ×2
pandas ×2
caching ×1
css ×1
css-counter ×1
flask ×1
html ×1
iis ×1
javascript ×1
matplotlib ×1
multilingual ×1
php ×1
promise ×1
qtranslate ×1
random ×1
seaborn ×1
sql ×1
sql-server ×1
t-sql ×1
typescript ×1
webpack ×1
wordpress ×1