我在 Lucidchart 应用程序中使用了以下乳胶:
\omega_{11}^{\ell}
我希望第一个1
颜色为红色,第二个1
颜色为绿色。我该如何实现?
我尝试了以下方法:
\omega_{1{red}1{green}}^{\ell}
但它并没有带来正确的结果。
我在 Lucidchart 应用程序中使用了以下乳胶:
\omega_{11}^{\ell}
我希望第一个1
颜色为红色,第二个1
颜色为绿色。我该如何实现?
我尝试了以下方法:
\omega_{1{red}1{green}}^{\ell}
但它并没有带来正确的结果。
我正在学习Python。我使用谷歌进行的研究没有对这里发生的事情进行任何描述。我正在做一些基本练习。
codewars 网站上的一个人把这个解决方案归咎于一个问题:
data=[[18, 20], [45, 2], [61, 12], [37, 6], [21, 21], [78, 9]]
def openOrSenior(data):
return ["Senior" if age >= 55 and handicap >= 8 else "Open" for (age, handicap) in data]
我无法理解他们如何使用元组来访问子列表元素。这在 Python 中叫什么?它是如何工作的?
for (age, handicap) in data
我正在学习 SQL。我的搜索没有取得成果,因为我认为我使用的术语不正确。
我在 Postgresql 中有一个带有日期时间列的表。我想要做的是在结果集中创建一个列,输出如下:Q2/'22
或Q4/'23
。
我尝试过使用+
,但这不起作用(我收到错误)。我不知道如何进一步进行。SQL有办法吗?
SELECT
name, COUNT(name),
DATE_TRUNC('quarter', date) AS quarterview,
CASE
WHEN DATE_TRUNC('quarter', date) = '2022-04-01 00:00:00'
THEN EXTRACT(quarter FROM DATE_TRUNC('quarter', date)) + '/\'' + EXTRACT(year FROM DATE_TRUNC('year', date))
END
FROM
mytable
有一个更好的方法吗?否则我将不得不为每个季度和每年编写案例。
另外,在 case 语句中,我尝试使用别名“quarterview”,但收到错误消息,指出“quarterview”不是列。有没有办法使用别名而不是DATE_TRUNC
多次写入?
我有这个数据框:
dfsupport = pd.DataFrame({'Date': ['8/12/2020','8/12/2020','13/1/2020','24/5/2020','31/10/2020','11/7/2020','11/7/2020'],
'Category': ['Table','Chair','Cushion','Table','Chair','Mats','Mats'],
'Sales': ['1 table','3chairs','8 cushions','3Tables','12 Chairs','12Mats','4Mats'],
'Paid': ['Yes','Yes','Yes','Yes','No','Yes','Yes',],
'Amount': ['93.78','$51.99','44.99','38.24','£29.99','29 21 only','18']
})
以表格形式显示如下:
Date Category Sales Paid Amount
0 8/12/2020 Table 1 table Yes 93.78
1 8/12/2020 Chair 3chairs Yes $51.99
2 13/1/2020 Cushion 8 cushions Yes 44.99
3 24/5/2020 Table 3Tables Yes 38.24
4 31/10/2020 Chair 12 Chairs No £29.99
5 11/7/2020 Mats 12Mats Yes 29 21 only
6 11/7/2020 Mats 4Mats Yes 18
我想删除上面的两个字符串元素。我学会了如何成功地将 $ 和 £ 替换为:
patternv='|'.join(re.escape(x) for x in ['$', '£'])
dfsupport['Amount'] = dfsupport['Amount'].str.replace(patternv,regex=True)
我现在想要替换“金额”列中包含“29 21 only”的条目。我的尝试是:
patterns="{r'(\d{1,})\s(\d{1,2})\D+' : r'\1 \2'}"
dfsupport['Amount']=dfsupport['Amount'].str.replace(patterns,regex=True)
但是我的尝试导致了错误:
Traceback (most recent call last):
File "/home/cloud/code/learning/howmany.py", line 160, in <module>
dfsupport['Amount'] = dfsupport['Amount'].str.replace(patternv,regex=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/cloud/.venv/lib/python3.12/site-packages/pandas/core/strings/accessor.py", line 136, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: StringMethods.replace() missing 1 required positional argument: 'repl'
我该如何解决?
我应该补充一点,我正在寻求输出为“29.21”
我有这个数据框:
dfsupport = pd.DataFrame({'Date': ['8/12/2020','8/12/2020','13/1/2020','24/5/2020','31/10/2020','11/7/2020','11/7/2020'],
'Category': ['Table','Chair','Cushion','Table','Chair','Mats','Mats'],
'Sales': ['1 table','3chairs','8 cushions','3Tables','12 Chairs','12Mats','4Mats'],
'Paid': ['Yes','Yes','Yes','Yes','No','Yes','Yes',],
'Amount': ['93.78','$51.99','44.99','38.24','£29.99','29 only','18']
})
我试图用空白替换货币符号,但下面的方法不起作用。
patternv='|'.join(['$', '£'])
dfsupport['Amount'] = dfsupport['Amount'].str.replace(patternv,'')
为什么这不起作用?
在上述之后打印数据框:
Date Category Sales Paid Amount
0 8/12/2020 Table 1 table Yes 93.78
1 8/12/2020 Chair 3chairs Yes $51.99
2 13/1/2020 Cushion 8 cushions Yes 44.99
3 24/5/2020 Table 3Tables Yes 38.24
4 31/10/2020 Chair 12 Chairs No £29.99
5 11/7/2020 Mats 12Mats Yes 29 only
6 11/7/2020 Mats 4Mats Yes 18
Date Category Sales Paid Amount
1 8/12/2020 Chair 3chairs Yes $51.99
4 31/10/2020 Chair 12 Chairs No £29.99
我确实遵循了这个问题,所以不确定为什么我的不起作用。
我正在学习 terraform,我不明白为什么变量count.index
没有被扩展。
当我运行terraform apply
EC2 实例的名称时VM[count.index]
为什么 [count.index] 没有扩展?我期待这个名字是VM0
我为测试创建的文件
main.tf
provider "aws" {
access_key = var.aws_access_key_id
secret_key = var.aws_secret_access_key
region = "us-east-1"
}
resource "aws_instance" "aws_vm" {
ami = var.ami
instance_type = var.type
count = var.number_of_instances
key_name = var.ami_key
tags = {
Name = "${var.name_tag}[count.index]"
}
}
我是 Terraform 的新手,正在练习创建我的第一个 terraform。我遇到了一个我不确定的错误,并在网上查看相同的错误,不清楚我应该做什么。感觉这里存在一个基本的“类型”问题。有人可以强调需要做什么以及为什么。
错误:
terraform validate
╷
│ Error: Missing resource instance key
│
│ on variables.tf line 32, in output "public_ip":
│ 32: value = aws_instance.my_rhel9_vm.public_ip
│
│ Because aws_instance.my_rhel9_vm has "count" set, its attributes must be accessed on specific instances.
│
│ For example, to correlate with indices of a referring resource, use:
│ aws_instance.my_rhel9_vm[count.index]
╵
╷
│ Error: Missing resource instance key
│
│ on variables.tf line 37, in output "instance_id":
│ 37: value = aws_instance.my_rhel9_vm.id
│
│ Because aws_instance.my_rhel9_vm has "count" set, its attributes must be accessed on specific instances.
│
│ For example, to correlate with indices of a referring resource, use:
│ aws_instance.my_rhel9_vm[count.index]
╵
main.tf
provider "aws" {
access_key = var.aws_access_key_id
secret_key = var.aws_secret_access_key
region = "us-east-1"
}
resource "aws_instance" "my_rhel9_vm" {
ami = var.ami //RHEL 9 AMI
instance_type = var.type
count = var.number_of_instances
key_name = var.ami_key_pair_name
tags = {
Name = "${var.name_tag}"
}
}
variables.tf
variable "ami" {
type = string
description = "RHEL 9 AMI ID in US-East-1"
default = "ami-05a5f6298acdb05b6"
}
variable "type" {
type = string
description = "Instance Type"
default = "t2.micro"
}
variable "name_tag" {
type = string
description = "Name of the EC2 instance"
default = "My EC2 RHEL 9 instance"
}
variable "number_of_instances" {
type = number
description = "Number of instances to be created"
default = 1
}
variable "ami_key_pair_name" {
type = string
description = "SSH Key Pair"
default = "tomcat"
}
output "public_ip" {
value = aws_instance.my_rhel9_vm.public_ip
description = "Public IP Address of EC2 instance"
}
output "instance_id" {
value = aws_instance.my_rhel9_vm.id
description = "Instance ID"
}
variable "aws_access_key_id" {}
variable "aws_secret_access_key" {}
#locals {
# ami = "ami-05a5f6298acdb05b6"
# type = "t2.micro"
# name_tag = "My EC2 RHEL 9 instance"
#}
我正在学习 SQL 并在 MySQL 中创建了以下数据集:
Create table Departments (DepartmentID int primary key, Name text);
insert into Departments values
(1001,'SRO'),
(2001,'Drs'),
(3001,'Accounting');
Create table Employees
(
EmployeeID int not null,
DepartmentID int not null,
ManagerID int,
Name varchar(50) not null,
Salary int not null,
primary key(EmployeeID),
foreign key (DepartmentID)
references Departments(DepartmentID)
);
insert into Employees values
(68319,1001,NULL,'Kayling','6000.00'),
(66928,3001,68319,'Blaze','2750.00'),
(67832,1001,68319,'Clare','2550.00'),
(65646,2001,68319,'Jonas','2957.00'),
(67858,2001,65646,'Scarlet','3100.00'),
(69062,2001,65646,'Frank','3100.00'),
(63679,2001,69062,'Sandrine','900.00'),
(64989,3001,66928,'Adelyn','1700.00'),
(65271,3001,66928,'Wade','1350.00');
我想找到每个部门的最高工资,研究了我看到的许多建议MAX
以这种形式运行的文章:
SELECT max(Salary),DepartmentID
FROM Employees
GROUP BY DepartmentID;
但是,鉴于此处答案中描述的操作顺序
FROM, including JOINs
WHERE
SELECT the row obtained by from and where in a temporary area for others
operation (and build the column alias)
DISTINCT
GROUP BY
HAVING
ORDER BY
LIMIT and OFFSET
return the final result
该MAX
函数在 之前调用GROUP BY
,这意味着MAX
将会在执行之前在整个表中工作GROUP BY
,根据我的理解,这应该导致表中存在单个最大值,该最大值应该是6000。然而,事实并非如此,我看到的结果在我想要的正确结构中令人困惑:
max(Salary) DepartmentID
6000 1001
3100 2001
2750 3001
不知怎的,该MAX
函数在 a 之后工作GROUP BY
,但也在由于GROUP BY
删除多个组行而丢失所有行之前工作。
如果我继续这种理解,就会给我带来更多问题。
如果GROUP BY
操作发生在 之前,SELECT
那么GROUP BY
将会删除每个行的所有行,只留下随机选择的DepartmentID
一行,这意味着当函数有机会运行时,它只会看到一个工资值,该值可以是任意值。值而不是每个部门的最大值。MAX
SELECT
我错过了什么使我的理解变得复杂?
我怎样才能将文本分成两部分,我想捕获第二个大写字母之前的所有文本
我有
nycTrSeven
nycPkExt
nycAbEchTrn
我想要这样的输出:
nycTr
nycPk
nycAb
在 SQL 中是否可能,或者我唯一的希望是使用像 Python 这样的编程语言?