我试图在我通过函数创建的条形图上注释标准消息。以下是代码:
hashbar <- function(x) {
suppressWarnings(library(stringr))
hash <- "#[A-Za-z0-9]{1,}"
hashtg <- str_extract_all(x$text, hash)
hashtg <- as.data.frame(unlist(hashtg))
hashtg <- as.data.frame(sort(table(hashtg), decreasing = TRUE)[1:15])
names(hashtg)[1] <- "Freq"
hashtg$hashtag <- rownames(hashtg)
rownames(hashtg) <- NULL
suppressWarnings(library(ggplot2))
suppressWarnings(library(RColorBrewer))
p <- ggplot(hashtg, aes(x=reorder(hashtag, Freq), y = Freq, fill = hashtag)) + geom_bar(stat="identity") +
geom_bar(width = 0.4) + xlab("Hashtags Used") + ylab("Number of responses") +
geom_text(aes(label=Freq), hjust = 1, colour = "white" ) +
ggtitle("Analysis of Most Frequently Used Hashtags") +
theme(plot.title=element_text(size=rel(1.2), lineheight = 1, face = …
Run Code Online (Sandbox Code Playgroud) 我有以下数据集:
structure(list(BRAND = c("BRANDA", "BRANDA", "BRANDA", "BRANDA",
"BRANDA"), VARIANT = c("VAR1", "VAR1", "VAR1",
"VAR1", "VAR1"), Noodles = c(20L, 100L, 10L, 0L,
50L), Peas = c(14L, 0L, 0L, 0L, 14L), milk = c(1710L, 468L,
1020L, 585L, 1710L)), row.names = c(NA, 5L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
我正在尝试为每个产品列导出非零的行数。所需的输出如下:
BRAND VARIANT Noodles Peas milk
1 BRANDA VAR1 4 2 5
Run Code Online (Sandbox Code Playgroud)
我曾尝试使用 dplyr,但不确定如何获取值不为零的计数。我不确定是否应该将所有零转换为 NA,这看起来不太直观……或者我是否应该使用过滤器来删除零。
a <- ndf %>% group_by(BRAND, VARIANT) %>% summarise_all(funs(n()))
Run Code Online (Sandbox Code Playgroud) 在我的网页中,我想通过 PHP 列出 mysql 中可用的所有数据库。
以下代码列出了所有数据库:
<?php
$link = mysql_connect('localhost', 'root', 'pass123');
$res = mysql_query("SHOW DATABASES");
while ($row = mysql_fetch_assoc($res)) {
echo $row['Database'] . "\n";
}
?>
Run Code Online (Sandbox Code Playgroud)
但是,我想'information_schema', 'mysql' and 'performance_schema'
从数据库列表中排除。
在 mysql 终端,我尝试了:
show schema_name as database from information_schema.SCHEMATA where schema_name NOT IN ('information_schema','mysql');
Run Code Online (Sandbox Code Playgroud)
但出现错误...未知的列名 schema_name。
我正在创建一个 API 来接收和处理图像。我必须以字节数组格式接收图像。以下是我要发布的代码:
方法 1 将图像发布到 api
with open("test.jpg", "rb") as imageFile:
f = imageFile.read()
b = bytearray(f)
url = 'http://127.0.0.1:5000/lastoneweek'
headers = {'Content-Type': 'application/octet-stream'}
res = requests.get(url, data=b, headers=headers)
##print received json response
print(res.text)
Run Code Online (Sandbox Code Playgroud)
我的 API:在 api 接收图像
@app.route('/lastoneweek', methods=['GET'])
def get():
img=request.files['data']
image = Image.open(io.BytesIO(img))
image=cv2.imread(image)
##do all image processing and return json response
Run Code Online (Sandbox Code Playgroud)
在我的 api 中,我尝试过,request.get['data']
request.params['data']
....我遇到了object has no attribute
错误。
我尝试将 bytearray 与图像的宽度和高度一起传递给 json,例如:
方法2:将图像发布到api
data = '{"IMAGE":b,"WIDTH":16.5,"HEIGHT":20.5}'
url = 'http://127.0.0.1:5000/lastoneweek'
headers …
Run Code Online (Sandbox Code Playgroud) 我正在使用情节。我制作的每个图形都隐藏了一半的 x 轴。即使我使用 x 轴的变量作为 y 轴,它也会发生。例如,考虑以下数据集:
structure(list(City = c("MUMBAI", "DELHI", "KOLKATTA", "HYDERABAD",
"PUNE", "BANGALORE", "AHMEDABAD", "LUCKNOW", "AGRA", "BHUBANESHWAR",
"GUWAHATI", "NAGPUR", "DELHIN.C.R", "MANGALORE", "INDORE"), OppLoss = c(48,
44, 41, 38, 56, 43, 44, 43, 42, 32, 31, 43, 47, 25, 41)), .Names = c("City",
"OppLoss"), row.names = c(32L, 13L, 26L, 17L, 35L, 5L, 2L, 27L,
1L, 8L, 16L, 33L, 14L, 30L, 18L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
我使用了以下代码:
plot_ly(n, x = OppLoss, y = City, name = OppLoss, mode = "markers", marker …
Run Code Online (Sandbox Code Playgroud) 我正在使用 Elasticsearch 6.4 和 Python 3。我正在处理图像,输出之一是 Numpy 数组。我正在尝试将 Numpy 数组以及图像分析中的其他数据字段索引到 Elasticsearch 中。我有三个字段:
它们看起来如下:
imagename: 123def321_1548492175.jpg
time_stamp: 1548492175 [
encod:
array([ -1.42405510e-01, 8.58794246e-03, 4.45950478e-02,
-1.81895699e-02, -5.53448014e-02, -1.73689388e-02,
-4.21237871e-02, -8.25227201e-02, 1.56264022e-01,
-3.99713218e-02, 1.60366639e-01, 4.53100577e-02,
-2.09424138e-01, -5.07910103e-02, -4.65360470e-04,
8.38596523e-02, -1.19933985e-01, -1.71518624e-01,
-1.26374453e-01 ])]
Run Code Online (Sandbox Code Playgroud)
实际的数组长度要长得多。当我获取索引时,它的定义如下:
{
"g6jy834005er" : {
"aliases" : { },
"mappings" : {
"images" : {
"dynamic" : "false",
"properties" : {
"encod" : {
"type" : "nested"
},
"imagename" : {
"type" : "text"
},
"time_stamp" …
Run Code Online (Sandbox Code Playgroud) 我正在使用openxlsx
r 来创建具有某些格式参数的 Excel 文件。以下是可重用的代码:
library(openxlsx)
wb <- createWorkbook()
addWorksheet(wb, "TestSheet")
df <- mtcars
df$Car <- row.names(mtcars)
row.names(df) <- NULL
df <- df[,c(length(df), 1:length(df)-1)]
forTopTit <- createStyle(fontColour = "#ffffff", fgFill = "#F4D03F",halign = "center",wrapText = TRUE,valign = "center")
forColHdr <- createStyle(fontColour = "#ffffff", fgFill = "#4F81BD",halign = "center",wrapText = TRUE,valign = "center")
forDatStl <- createStyle(fontColour = "#ffffff", halign="center")
writeData(wb,"TestSheet", "THIS IS A TEST MESSAGE", startCol = 1,startRow = 1,colNames = FALSE, rowNames = TRUE,
headerStyle = forTopTit,borders = "surrounding",borderStyle …
Run Code Online (Sandbox Code Playgroud) 我正在从mysql中检索数据,并希望将localStorage中的每一行数据保存为数组.以下是我在javascript端收到的嵌套数组.
arr = [{image_id: "80", imagename: "Image1",firstx: "267", firsty: "403"},
{image_id: "80", imagename: "Image1",firstx: "320", firsty: "470"},
{image_id: "80", imagename: "Image2",firstx: "126", firsty: "237"}
]
Run Code Online (Sandbox Code Playgroud)
从这里我想删除image_id,imagename,firstx和firsty并返回一个数组的结果,并且只包含每个数组的值.期望的输出是
newarr =[[80,Image1,267,403],[80,Image1,320,470],[80,Image2,126,237]]
Run Code Online (Sandbox Code Playgroud)
我做了以下事情:
var newarr = [];
for (var i = 0, l = arr.length; i < l; i++) {
var keys = Object.keys(arr[i]);
for (var j = 0, k = keys.length; j < k; j++) {
newarr.push(arr[i][keys[j]]);
}
}
console.log(newarr)
Run Code Online (Sandbox Code Playgroud)
这将返回作为数组的每个元素.结果数组将作为嵌套数组推送到localStorage.