爱冒险

文章 评论 浏览 29

爱冒险 2025-02-10 19:42:37
for index, row in df.iterrows():
if row['Order description'] == 'Internet Port Charge':
    row['amount'] = row['amount'] * 0.33
else:
    row['amount'] = row['amount'] * 111.9

您必须使用.iterrows()循环浏览数据框,然后您可以单独访问每行

.iterrows()是非常重要的资源。

for index, row in df.iterrows():
if row['Order description'] == 'Internet Port Charge':
    row['amount'] = row['amount'] * 0.33
else:
    row['amount'] = row['amount'] * 111.9

You must loop through the DataFrame using .iterrows() then you can access each row individually

.iterrows() is very resource intensive though.

这是否是循环浏览熊猫中的数据帧并乘以2种不同条件的方法?

爱冒险 2025-02-10 15:46:01

您需要一系列布尔值来跟踪ListView中每个项目的状态,

请尝试更改

if(urgent == true) {
   newView.setBackgroundColor(Color.RED);
   textView.setTextColor(Color.WHITE);
}

if(urgent[position]) {
    newView.setBackgroundColor(Color.RED);
    textView.setTextColor(Color.WHITE);
} else {
    //Put here the default colors
    newView.setBackgroundColor(  );
    textView.setTextColor(  );
}

问题,也不需要执行,如果(boolean == true) < <代码> if(boolean)就足够了

You need an array of booleans to keep track of the state for each item in the listview

Try changing

if(urgent == true) {
   newView.setBackgroundColor(Color.RED);
   textView.setTextColor(Color.WHITE);
}

To

if(urgent[position]) {
    newView.setBackgroundColor(Color.RED);
    textView.setTextColor(Color.WHITE);
} else {
    //Put here the default colors
    newView.setBackgroundColor(  );
    textView.setTextColor(  );
}

this should fix the issue, also you don't need to do if(boolean == true) if(boolean) is enough

Android Studio:无法根据布尔更改背景颜色和文本颜色

爱冒险 2025-02-10 09:29:27

与往常一样,系统调用返回值在rax中。参见是unix&amp; Linux系统致电I386和X86-64

请注意,sys_brkbrk/sbrk posix functions的接口略有不同;请参阅 c库/内核差异brk(2 )人页。具体而言, linux sys_brk sets 程序折断; ARG和返回值都是指示。参见 issembly x86 brk()brk()该答案需要投票,因为这是该问题上唯一的好问题。


您问题的另一个有趣的部分是:

我在这种情况下不太了解RCX寄存器中的值

在这种情况下, “> syscall / 指令旨在允许内核恢复用户空间执行,但仍然很快。

syscall不做任何负载或商店,它仅修改寄存器。它没有使用特殊寄存器保存返回地址,而只是使用常规整数寄存器。

rcx = rip and rflags在内核返回到您的用户空间代码之后,这不是一个巧合。此不是的唯一方法是,如果ptrace系统调用修改了该过程已保存的rcxr11值在内核内。 (ptrace是系统调用GDB使用)。在这种情况下,Linux将使用IRET而不是sysret返回用户空间,因为较慢的通用案例iret可以做到这一点。 (请参阅如果您在64位代码中使用32位INT 0x80 Linux ABI会发生什么?对于Linux的System-call输入点的某些演练。主要是从32位到32位的入口点 在64位过程中syscall


流程,不是 代码> syscall :

  • 设置rcx = rip,r11 = rflags(因此,在执行syscall之前,内核甚至不可能看到这些regs的原始值)。

  • masks rflags带有从配置寄存器(ia32_fmask msr)的预配置掩码。这使内核可以禁用中断(如果)直到完成swapgs和设置rsp指向内核堆栈。即使cli是入口点处的第一个指令,也会有一个脆弱性窗口。您还可以免费获得cld通过掩盖df SO REP MOVS/STOS即使用户空间也向上移动已经使用了std

    有趣的事实:AMD的第一个提议syscall/swapgs设计没有掩盖rflags,而是他们在AMD64邮件列表上的内核开发人员的反馈(在2000年,第一个硅之前的几年)。

  • 跳到配置的syscall输入点(设置CS:RIP = ia32_lstar)。我认为旧的cs值在任何地方都没有保存。

  • 它无能为它的价值来自用户空间。

因此,syscall的设计需要一个clobbers注册的系统通话ABI,这就是为什么值是它们的原因。

The system call return value is in rax, as always. See What are the calling conventions for UNIX & Linux system calls on i386 and x86-64.

Note that sys_brk has a slightly different interface than the brk / sbrk POSIX functions; see the C library/kernel differences section of the Linux brk(2) man page. Specifically, Linux sys_brk sets the program break; the arg and return value are both pointers. See Assembly x86 brk() call use. That answer needs upvotes because it's the only good one on that question.


The other interesting part of your question is:

I do not quite understand the value in the rcx register in this case

You're seeing the mechanics of how the syscall / sysret instructions are designed to allow the kernel to resume user-space execution but still be fast.

syscall doesn't do any loads or stores, it only modifies registers. Instead of using special registers to save a return address, it simply uses regular integer registers.

It's not a coincidence that RCX=RIP and R11=RFLAGS after the kernel returns to your user-space code. The only way for this not to be the case is if a ptrace system call modified the process's saved rcx or r11 value while it was inside the kernel. (ptrace is the system call gdb uses). In that case, Linux would use iret instead of sysret to return to user space, because the slower general-case iret can do that. (See What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code? for some walk-through of Linux's system-call entry points. Mostly the entry points from 32-bit processes, not from syscall in a 64-bit process, though.)


Instead of pushing a return address onto the kernel stack (like int 0x80 does), syscall:

  • sets RCX=RIP, R11=RFLAGS (so it's impossible for the kernel to even see the original values of those regs before you executed syscall).

  • masks RFLAGS with a pre-configured mask from a config register (the IA32_FMASK MSR). This lets the kernel disable interrupts (IF) until it's done swapgs and setting rsp to point to the kernel stack. Even with cli as the first instruction at the entry point, there'd be a window of vulnerability. You also get cld for free by masking off DF so rep movs / stos go upward even if user-space had used std.

    Fun fact: AMD's first proposed syscall / swapgs design didn't mask RFLAGS, but they changed it after feedback from kernel developers on the amd64 mailing list (in ~2000, a couple years before the first silicon).

  • jumps to the configured syscall entry point (setting CS:RIP = IA32_LSTAR). The old CS value isn't saved anywhere, I think.

  • It doesn't do anything else, the kernel has to use swapgs to get access to an info block where it saved the kernel stack pointer, because rsp still has its value from user-space.

So the design of syscall requires a system-call ABI that clobbers registers, and that's why the values are what they are.

X86-64 Linux系统为什么调用RCX,该值是什么意思?

爱冒险 2025-02-10 07:37:21

我假设面包等是标识符。我不知道应该代表什么空白。另外,我认为您的意思是使用=而不是==。无论如何,这似乎是一个使用元组的匹配的好地方:

cols = col1, col2

match cols:
    case (bread, col2):
        if col2 > 1:
            bread_alert = 'alert_bread'

...等等。组合警报就像将它们附加到空列表中一样简单。

I'm assuming bread and such are identifiers. I don't know what blank is supposed to represent. Also, I think you mean to use = instead of ==. Anyways, this seems like a great place to use match with a tuple:

cols = col1, col2

match cols:
    case (bread, col2):
        if col2 > 1:
            bread_alert = 'alert_bread'

... and so on. Combining the alerts would be as simple as appending them to an empty list.

python在不同场合增加多个错误

爱冒险 2025-02-10 04:58:00

尝试此解决方案

use Carbon\Carbon;
...

$current_month = Carbon::now()->format('m');
$current_year = Carbon::now()->format('Y');

DB::table('exercises')
    ->select('id', 'day')
    ->where('user_id', Auth::user()->id)
    ->whereMonth('day', $current_month)
    ->whereYear('day', $current_year)
    ->distinct()
    ->count();

Try this solution

use Carbon\Carbon;
...

$current_month = Carbon::now()->format('m');
$current_year = Carbon::now()->format('Y');

DB::table('exercises')
    ->select('id', 'day')
    ->where('user_id', Auth::user()->id)
    ->whereMonth('day', $current_month)
    ->whereYear('day', $current_year)
    ->distinct()
    ->count();

从存储的日期中提取月份

爱冒险 2025-02-10 02:23:09

如果您使用Intellij Idea并有此错误,请尝试使用此错误。

  1. 命令 + (打开首选项)
  2. 构建,执行,部署构建工具 gradle
  3. Gradle JVM →将其更改为适当的版本

If you're using IntelliJ IDEA and having this error, try this.

  1. Command + , (Open Preferences)
  2. Build, Execution, DeploymentBuild ToolsGradle
  3. Gradle JVM → Change it to a proper version

班级是由Java环境的最新版本编译的

爱冒险 2025-02-10 01:27:51

大约一年后回答我的问题。这是我的解决方案,也是一个简单的解决方案。

我推荐了@Time推荐的想法。

gitlab pipeline的环境

  • 首先创建环境,例如开发,分期,生产等,
  • 创建变量,但分配给不同的环境

“在此处输入图像描述”

  • 您可以设置具有相同名称的变量,但分配给了不同的环境。

使用时,您可以将以下代码添加到每个任务

staging_build:
  stage: build
  environment:
    name: staging
  script:
    - echo ${AWS_ACCESS_KEY_ID}
  only:
    - staging

production_build:
  stage: build
  environment:
    name: production
  script:
    - echo ${AWS_ACCESS_KEY_ID}
  only:
    - main

Answer my question after about 1 year. Here is my solution, and a simple solution.

I refered the idea from @Time recommended.

gitlab pipeline's environments are similar concept of CircleCI's context , if you are familar it.

  • create environments first, such as develop, staging, production, etc
  • create variables but assigned to different environments

enter image description here

  • you can set the variables with same names, but assigned to different environments.

When use it, you can add below codes to each task

staging_build:
  stage: build
  environment:
    name: staging
  script:
    - echo ${AWS_ACCESS_KEY_ID}
  only:
    - staging

production_build:
  stage: build
  environment:
    name: production
  script:
    - echo ${AWS_ACCESS_KEY_ID}
  only:
    - main

如果gitlab-ci.yml中的条件变量

爱冒险 2025-02-09 20:45:23

您收到错误消息吗?

还有AVG(人口)和GT; country_name ='Miami-Dade'是不正确的。

您需要一个城市,该城市的人口高于“ County_name”迈阿密戴德市的城市平均人口。如此人口&gt; AVG(从USCITY中选择country_name ='Miami-Dade')

query = """
SELECT DISTINCT city
FROM uscity 
WHERE city != state_name
AND population > avg(select population from uscity where country_name = 'Miami-Dade')
AND city like '% %'
"""

Do you get an error message ?

Also the avg(population) > country_name = 'Miami-Dade' is incorrect.

You need a city which has a population above the average population of the cities in 'county_name' Miami-Dade. So population > avg(select population from uscity where country_name = 'Miami-Dade')

query = """
SELECT DISTINCT city
FROM uscity 
WHERE city != state_name
AND population > avg(select population from uscity where country_name = 'Miami-Dade')
AND city like '% %'
"""

获得更高的平均城市人口,这些城市属于某个国家名称

爱冒险 2025-02-08 10:38:15

它们称为类型提示,它们启用了函数的参数和返回类型的注释。

https://peps.python.org/pep-0484/

They're called type hints, and they enable annotating the types of the parameters and return types of functions.

https://peps.python.org/pep-0484/

在方法构建中使用无和自关键词

爱冒险 2025-02-07 19:48:02

该分组看起来应该在Session_ID_Current_user上,除了AVG Max(ED)以外的所有字段(ED)都存在,以查看是否有名称

SELECT t.session_id_current_user,
       max(t.name), max(email)...
       , AVG(t.spent_time) 
FROM table t 
where exists (select 1 from t t1 where t1.session_id_current_user = t.session_id_current_user and t1.name is not null)
group by t.session_id_current_user;

The grouping looks like it should be on session_id_current_user with all fields other than avg max(ed) with an existence check to see if there is a name eg

SELECT t.session_id_current_user,
       max(t.name), max(email)...
       , AVG(t.spent_time) 
FROM table t 
where exists (select 1 from t t1 where t1.session_id_current_user = t.session_id_current_user and t1.name is not null)
group by t.session_id_current_user;

没有第一个零单元的组

爱冒险 2025-02-07 15:54:42

您可以使用 >:

df2 = df.filter(regex='(?i)austria')  # (?i) makes the search case insensitive

示例:

df = pd.DataFrame(columns=['austria something', 'something austria',
                           'another austria', 'unrelated', 'Austria again'],
                  index=[0])

df.filter(regex='(?i)austria')

输出:

  austria something something austria another austria Austria again
0               NaN               NaN             NaN           NaN

You can use filter:

df2 = df.filter(regex='(?i)austria')  # (?i) makes the search case insensitive

Example:

df = pd.DataFrame(columns=['austria something', 'something austria',
                           'another austria', 'unrelated', 'Austria again'],
                  index=[0])

df.filter(regex='(?i)austria')

output:

  austria something something austria another austria Austria again
0               NaN               NaN             NaN           NaN

基于列标题的新数据帧

爱冒险 2025-02-07 04:04:05

我们将内存块复制到类型Void*。

的变量

小心。您正在复制到 void *的内存。但是,是的,您正在复制内存的。特别是,您不是分配值,因此您不可能转换值

将它们转换为int类型后,我们将获得大量数字。

同样,您必须小心自己的语言。您没有将任何内容转换为int类型。您将两个指针从void *类型转换为int *类型。您转换了指针。您做了不是转换尖头值!

如果您说过,

float fa = 2.11;
int ia = (int)fa;

您将将浮点数2.11转换为整数2。但这不是您所做的。

ieee-754浮点。 (那些看起来疯狂的碎特实际上代表了数字2.11是一个有趣的故事,但是超出了这个答案的范围。)和十进制的十六进制数量0x40070a3d在十进制中是1074203197您看到的号码。

当您说

ffa = (int*)a;

自己是不是说:“嘿,编译器,那些代表浮点数为2.11的位时,我希望您将它们转换为我的整数。” (再次,为此,您需要int ia =(int)fa;。)不,这行说的是“嘿,编译器,该指针a a 指出一些代表浮点数的位,我想假装它们是指向整数的指针。”

换句话说,您没有更改尖头的位。而且,在某种程度上,您也没有更改指针:ffa指向内存中a do的位置完全相同的位置。但是,您非常重要的改变是对尖头的解释a是通往内存中一个点的指针,我们希望有类型float的值在内存中,我们期望有类型int的值。

因此,如果您说

printf("%f\n", *a);

自己有指针,a,它假定指向float,然后使用*来“将目录of“指针,因此您可以获取尖头值,并使用%f进行打印,然后看到2.11

但是,当您说

printf("ffa = %d\n", *ffa);

自己有指针时,ffa,它被认为指向int,然后使用*“取”内容of“指针,因此您可以获取指向值,并使用%D进行打印,然后看到1074203197

您已经使用指针采取相同的位模式,坐在记忆中的同一位置,并以两种不同的方式解释它。
被解释为类型float,位模式0x40070a3d为2.11。
被解释为类型int,位模式0x40070a3d是1074203197。

这是通用指针的常见(且功能强大的),尽管现在您开始理解它,我必须离开您的注意事项。像我们在这里所做的那样,在内存中采用位模式并将其重新诠释为不同的类型,实际上比这个问题使其看起来更复杂。在实践中,有两种现实世界中的并发症会发挥作用, Alignment 严格的混叠 。在某个时候,您可能想了解有关这些信息的更多信息。

We copy blocks of memory into variables of type void*.

Careful. You are copying into memory pointed to by variables of type void *. But, yes, you are copying blocks of memory. In particular, you are not assigning values, and therefore you have no possibility of converting values.

After converting them to int type, we get huge numbers.

Again, you have to be careful with your language. You did not convert anything to int type. You converted two pointers from void * type to int * type. You converted the pointers. You did not convert the pointed-to values!

If you had said

float fa = 2.11;
int ia = (int)fa;

you would have converted the floating-point number 2.11 to the integer 2. But that's not what you did.

In IEEE-754 floating point, the number 2.11 is represented by the bit pattern 0x40070a3d. (How it is that those crazy-looking bits actually represent the number 2.11 is a fascinating story, but beyond the scope of this answer.) And the hexadecimal number 0x40070a3d in decimal is 1074203197, which is precisely the number you saw.

When you say

ffa = (int*)a;

you are not saying, "Hey compiler, those bits representing the floating-point number 2.11, I want you to convert them to an integer for me." (Again, to do that, you'd want int ia = (int)fa;.) No, what this line says is "Hey, compiler, that pointer a pointing to some bits representing a floating-point number, I want to pretend they're a pointer pointing to an integer."

In other words, you did not change the pointed-to bits. And, in a way, you didn't change the pointer, either: ffa points to the exact same spot in memory that a does. But what you very importantly changed was the interpretation of the pointed-to bits. a is a pointer to a spot in memory where we expect there to be a value of type float, while ffa is a pointer to a spot in memory where we expect there to be a value of type int.

So if you say

printf("%f\n", *a);

you have a pointer, a, which is assumed to point to a float, and you use * to "take the contents of" the pointer, so you fetch the pointed-to value, and print it using %f, and you see 2.11.

But when you say

printf("ffa = %d\n", *ffa);

you have a pointer, ffa, which is assumed to point to an int, and you use * to "take the contents of" the pointer, so you fetch the pointed-to value, and print it using %d, and you see 1074203197.

You have used pointers to take the same bit pattern, sitting in the same spot in memory, and interpret it in two different ways.
Interpreted as type float, the bit pattern 0x40070a3d is 2.11.
Interpreted as type int, the bit pattern 0x40070a3d is 1074203197.

This is a common (and powerful) use of pointers, although now that you're starting to understand it, I have to leave you with some cautions. Taking bit patterns in memory and reinterpreting them as different types, as we've been doing here, is actually a little more complicated than this question has made it look. In practice, there are two real-world complications that come into play, alignment and strict aliasing. At some point you may want to learn more about those.

将void*转换为int*

爱冒险 2025-02-07 02:09:03

我假设this.loadgpsCoordinates();返回可观察的(如果不是这样,则可以这样做)

private coordinatesSubject = new ReplaySubject<any>(1)

ngOnInit() {
  this.loadGpsCoordinates().pipe(
    tap( data => this.coordinatesSubject.next(data))
  ).subscribe()
}

private ngAfterViewInit(data) { 
 
 this.coordinatesSubject().subscribe( data => {
    // data would be use below
    var elem = document.getElementById('map');
    if (elem != null) {
      this.map = new google.maps.Map(elem, {
        center: { lat: -32.3881373, lng: 55.4343223 },
        zoom: 17,
        disableDefaultUI: true
      });
     }
  })
}

注意:我没有添加takeuntil(doctioned $)但是您可以单独查找 - 删除组件时,它用于从服务中取消订阅

I'm assuming this.loadGpsCoordinates(); returns an Observable (if not it could be made to do so)

private coordinatesSubject = new ReplaySubject<any>(1)

ngOnInit() {
  this.loadGpsCoordinates().pipe(
    tap( data => this.coordinatesSubject.next(data))
  ).subscribe()
}

private ngAfterViewInit(data) { 
 
 this.coordinatesSubject().subscribe( data => {
    // data would be use below
    var elem = document.getElementById('map');
    if (elem != null) {
      this.map = new google.maps.Map(elem, {
        center: { lat: -32.3881373, lng: 55.4343223 },
        zoom: 17,
        disableDefaultUI: true
      });
     }
  })
}

Note: I didn't add a takeUntil(destroyed$) but you can look that up separately - it's used for unsubscribing from the service when the component is removed

等待ngoninit在ngafterviewinit内部完成

爱冒险 2025-02-06 23:58:25

现在一切都很好。我只是从Android手机重置应用程序的数据。对不起,尽管我别无选择,因为我发现问题了几个小时。

It's all good now. I just reset the data of the application from my android phone. I'm sorry though I had no option left because I was finding the problem for hours.

无法在App Widget(Android12)中执行悬念

爱冒险 2025-02-06 19:44:48

使用 dataclasses 。另外,它允许您应用类型限制(又称“类型提示”)。

from dataclasses import dataclass

@dataclass
class Holder:
    obj: your_type # Need any type? Use "obj: object" then.

def foo(ref: Holder):
    ref.obj = do_something()

我同意人们的看法,在大多数情况下,您最好考虑不要使用它。

但是,当我们谈论 上下文 ,这是值得的知道这种方式。

您可以设计一个明确的上下文类。当原型设计时,我更喜欢数据类别,只是因为它很容易来回序列化。

Use dataclasses. Also, it allows you to apply type restrictions (aka "type hints").

from dataclasses import dataclass

@dataclass
class Holder:
    obj: your_type # Need any type? Use "obj: object" then.

def foo(ref: Holder):
    ref.obj = do_something()

I agree with folks that in most cases you'd better consider not to use it.

And yet, when we're talking about contexts, it's worth to know that way.

You can design an explicit context class though. When prototyping, I prefer dataclasses, just because it's easy to serialize them back and forth.

如何通过引用传递变量?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文