A.append([(float(a) + float(b) + float(c))/3,
(float(d) + float(e) + float(f))/3,
(float(g) + float(h) + float(i))/3,
(float(j) + float(k) + float(l))/3,
(float(m) + float(n) + float(o))/3,
(float(p) + float(q) + float(r))/3,
(float(s) + float(t) + float(u))/3])
def mean(A):
positives = [b for b in A if b >= 0]
E.append((len(positives)) / (len(A))*100)
if positives:
return sum(positives) / len(positives)
else:
return 0
C = map(mean, zip(*A))
print C
#3 sigma check
def sigma(A):
positives = [b for b in A if b …Run Code Online (Sandbox Code Playgroud) 我第一次在 python 中工作,基本上我试图让这些标签在正确的列和正确的行中对齐,但由于某种原因它不会向下移动行,列也不正确。任何帮助将非常感激!
代码:
from tkinter import *
import sys
#Setup GUI
#Create main window
main = Tk();
#Create title of main window
main.title = "Waterizer 1.0";
#Create default size of main window
main.geometry("1024x768");
#Lets get a fram to stick the data in we plan on using
mainApp = Frame(main);
#Snap to grid
mainApp.grid();
#Font for main labels
labelFont = ('times', 20, 'bold');
#Label for the Power
powerLabel = Label(mainApp, text="Power Status");
powerLabel.config(fg="Red", bd="1");
powerLabel.config(font=labelFont);
powerLabel.grid( row=0,column=20,columnspan=4, sticky = W); …Run Code Online (Sandbox Code Playgroud) 我正在对一个数据集进行探索性分析,其中包括过去 20 年中游戏数量以及每个平台的销量。
我想选择在任天堂平台上发布的所有游戏,我为实现这一目标所做的工作是:
dfNintendo <- dfNintendo[dfNintendo$Platform=="GBA", ]
Run Code Online (Sandbox Code Playgroud)
它仅用于提取在 Nintendo GBA 上发布的游戏,但我不知道如何同时提取具有与 GBA 不同的标签的多行,我尝试过:
dfNintendo <- dfNintendo[dfNintendo$Platform=="GBA" |
dfNintendo$Platform=="Wii" |
dfNintendo$Platform=="WiiU", ]
Run Code Online (Sandbox Code Playgroud)
但它不起作用,我最终得到一个空的 data.frame。
我有一张<p-table>桌子sortMode="multiple"。我想在页面首次显示时指定两列作为默认排序。如果我设置 sortMode="single",它可以通过指定 sortField="year" [sortOrder]="-1" 选项来工作(例如,标题显示为选中状态,列已排序)。多列相当于什么?
类似的示例代码(取自https://www.primefaces.org/primeng/showcase/#/table/sort)
<h3>Multi Sort with MetaKey</h3>
<p-table [columns]="cols" [value]="cars2" sortMode="multiple">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns" [pSortableColumn]="col.field">
{{col.header}}
<p-sortIcon [field]="col.field"></p-sortIcon>
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
Run Code Online (Sandbox Code Playgroud)
export class TableSortDemo implements OnInit {
cars1: Car[];
cars2: Car[];
cars3: Car[];
cols: any[];
constructor(private carService: CarService) { }
ngOnInit() {
this.carService.getCarsSmall().then(cars => this.cars1 = cars);
this.carService.getCarsSmall().then(cars => this.cars2 …Run Code Online (Sandbox Code Playgroud) Coding,Value,Meaning,54-1.0,54-2.0,431-2.0,212-0.0,212-1.0
1,1,Yes,0.4,0.3,0.7,0.1,0.6
2,0,Other job (free text entry),0,0.7,0.3,0.7,0.8
2,1,Managers and Senior Officials,0.5,0.2,0.4,0.7,0.7
2,11,Corporate Managers,0.1,0.7,0.4,0.2,0.4
2,111,Corporate Managers And Senior Officials,0,0.8,0.8,0.4,0.8
2,1111,Senior officials in national government,0.9,0.6,0.4,0.2,0.9
2,1111001,AM (National Assembly),0.8,0.3,0.2,0,0.2
2,1111002,Ambassador (Foreign and Commonwealth Office),0.9,0.9,0.7,0.1,0.2
2,1111003,Band 0 (Health and Safety Executive),0.6,0.4,0,0.4,0.8
2,1111004,Band 1B (Meteorological Office),0.6,0.1,0.6,1,0.8
Run Code Online (Sandbox Code Playgroud)
我有一个像上面这样的 csv.gz 文件。我想按匹配某些字符串的名称提取列,例如,列名称匹配“54-”和“212-”。
我找到了如下解决方案,但我想知道是否可以对其进行修改,以便它可以提取与字符串列表中的任何元素匹配的列,例如“含义”、“54-”、“212-”。
zcat test.csv.gz |awk -F, 'NR==1{for(i=1;i<=NF;i++)if($i~/54-/)f[n++]=i}{for(i=0;i<n;i++)printf"%s%s",i?" ":"",$f[i];print""}'
Run Code Online (Sandbox Code Playgroud)
我还想将其保存到 csv.gz 文件中。但是通过> outputfile.csv在最后添加,我不能用逗号分隔。我想知道我应该把OFS=","这个命令放在哪里?
示例输出如下(在 csv.gz 文件中)
Meaning,54-1.0,54-2.0,212-0.0,212-1.0
Yes,0.4,0.3,0.1,0.6
Other job (free text entry),0,0.7,0.7,0.8
Managers and Senior Officials,0.5,0.2,0.7,0.7
Corporate Managers,0.1,0.7,0.2,0.4
Corporate Managers And Senior Officials,0,0.8,0.4,0.8 …Run Code Online (Sandbox Code Playgroud) 我想在 BASH 脚本中实现以下功能
当前代码
#!/bin/bash
Var=()
Var=(Title Album Song Rating 1 2 3 4 5 6 7 8 9 10 11 12 13)
echo " ${Var[@]}"
Run Code Online (Sandbox Code Playgroud)
输出:
Title Album Song Rating 1 2 3 4 5 6 7 8 9 10 11 12 13
Run Code Online (Sandbox Code Playgroud)
但是我想要实现的是在每 4 个元素之后并在相等的列中换行。
Title Album Song Rating
1 2 3 4
5 6 7 8
10 11 12 13
Run Code Online (Sandbox Code Playgroud) 如何将 COD 列中的值拆分为长度不同的 3 列?特别是如下所示,我需要第一列上有一个数字,第二列上有 2 个数字,第三列上有 3 个数字。任何想法?
COD CODA CODB CODC
140022 1 40 022
140031 1 40 031
140032 1 40 032
140033 1 40 033
140034 1 40 034
140035 1 40 035
140036 1 40 036
Run Code Online (Sandbox Code Playgroud)
谢谢!
数据框看起来像
y1 x2 x3 x4 x5
2 3 5 2 5
11 13 34 4 4
21 3 45 55 89
Run Code Online (Sandbox Code Playgroud)
研究需要在此数据框x2中添加另一个名为x1的列,并使用特定的字符串z填充所有观察值。输出应如下所示:
y1 x1 x2 x3 x4 x5
2 z 3 5 2 5
11 z 13 34 4 4
21 z 3 45 55 89
Run Code Online (Sandbox Code Playgroud)
帮忙,因为我尝试在此论坛上进行搜索但无法找到它。