大姐,你呐

文章 评论 浏览 28

大姐,你呐 2025-02-11 04:21:13

编辑2017

如评论和@Alexander所示,目前,将系列值添加为数据框的新列的最佳方法可以使用assign:

df1 = df1.assign(e=pd.Series(np.random.randn(sLength)).values)

<强>编辑2015
有些人报告使用此代码获取 setterwithCopyWarning
但是,该代码仍然完美地运行了当前的熊猫版本0.16.1。

>>> sLength = len(df1['a'])
>>> df1
          a         b         c         d
6 -0.269221 -0.026476  0.997517  1.294385
8  0.917438  0.847941  0.034235 -0.448948

>>> df1['e'] = pd.Series(np.random.randn(sLength), index=df1.index)
>>> df1
          a         b         c         d         e
6 -0.269221 -0.026476  0.997517  1.294385  1.757167
8  0.917438  0.847941  0.034235 -0.448948  2.228131

>>> pd.version.short_version
'0.16.1'

setterWithCopyWarning 旨在告知数据框架副本上可能无效的分配。它不一定说您做错了(它可能会触发误报),但是从0.13.0开始,您知道有更多的方法出于相同的目的。然后,如果收到警告,只需遵循其建议:尝试使用.loc [row_index,col_indexer] = value而不是

>>> df1.loc[:,'f'] = pd.Series(np.random.randn(sLength), index=df1.index)
>>> df1
          a         b         c         d         e         f
6 -0.269221 -0.026476  0.997517  1.294385  1.757167 -0.050927
8  0.917438  0.847941  0.034235 -0.448948  2.228131  0.006109
>>> 

,这是当前更有效的方法,例如 pandas docs


所述

中 系列:

df1['e'] = pd.Series(np.random.randn(sLength), index=df1.index)

Edit 2017

As indicated in the comments and by @Alexander, currently the best method to add the values of a Series as a new column of a DataFrame could be using assign:

df1 = df1.assign(e=pd.Series(np.random.randn(sLength)).values)

Edit 2015
Some reported getting the SettingWithCopyWarning with this code.
However, the code still runs perfectly with the current pandas version 0.16.1.

>>> sLength = len(df1['a'])
>>> df1
          a         b         c         d
6 -0.269221 -0.026476  0.997517  1.294385
8  0.917438  0.847941  0.034235 -0.448948

>>> df1['e'] = pd.Series(np.random.randn(sLength), index=df1.index)
>>> df1
          a         b         c         d         e
6 -0.269221 -0.026476  0.997517  1.294385  1.757167
8  0.917438  0.847941  0.034235 -0.448948  2.228131

>>> pd.version.short_version
'0.16.1'

The SettingWithCopyWarning aims to inform of a possibly invalid assignment on a copy of the Dataframe. It doesn't necessarily say you did it wrong (it can trigger false positives) but from 0.13.0 it let you know there are more adequate methods for the same purpose. Then, if you get the warning, just follow its advise: Try using .loc[row_index,col_indexer] = value instead

>>> df1.loc[:,'f'] = pd.Series(np.random.randn(sLength), index=df1.index)
>>> df1
          a         b         c         d         e         f
6 -0.269221 -0.026476  0.997517  1.294385  1.757167 -0.050927
8  0.917438  0.847941  0.034235 -0.448948  2.228131  0.006109
>>> 

In fact, this is currently the more efficient method as described in pandas docs


Original answer:

Use the original df1 indexes to create the series:

df1['e'] = pd.Series(np.random.randn(sLength), index=df1.index)

如何在现有数据框架中添加新列

大姐,你呐 2025-02-10 23:29:12

您的项目文件很可能指定&lt; targetFramework&gt; net6.0&lt;/targetFramework&gt;。将其更改为&lt; targetFramework&gt; net6.0-windows&lt;/targetFramework&gt;然后重试。
您也可能会感兴趣的是,如果&lt; usewindowsforms&gt; true&lt;/usewindowsforms&gt;已指定并LT; outputType&gt;不存在,您有一个具有Winforms依赖性的类库。

Quite possibly, your Project file specifies <TargetFramework>net6.0</TargetFramework>. Change this to <TargetFramework>net6.0-windows</TargetFramework> and try again.
It might also interest you to know that if <UseWindowsForms>true</UseWindowsForms> has been specified and <OutputType> is absent, you have a class Library with WinForms dependencies.

所有需要Net6.0的Nuget软件包与Net6.0不兼容。即使完成Windows重置

大姐,你呐 2025-02-10 20:48:51

像这样将“ cookie”涂在标题字典中。

headers = {
    "User-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
    "cookie":"AHWqTUlhftkLIuXSbIVa5uKh77iLa_kw1Tx9rkm3xTMos06ERQq3MgXWSdg7-iCp9WA"
}

您可以从浏览器的DevTools获得cookie。转到网站,切换到“应用程序”选项卡。展开cookie部分,然后复制cookie值。

我还建议您在代码之间也添加睡眠间隔。为了使用此功能,您将必须在脚本的顶部添加导入时间

time.sleep(2)

Apply "Cookie" in the headers dictionary like this.

headers = {
    "User-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
    "cookie":"AHWqTUlhftkLIuXSbIVa5uKh77iLa_kw1Tx9rkm3xTMos06ERQq3MgXWSdg7-iCp9WA"
}

You can get a cookie from the DevTools of the browser. Go to the website, switch to the Application tab. Expand the Cookie section and then copy the cookie value.

enter image description here

I will also suggest you to add sleep intervals in between your code too. To use this, you will have to add import time at the top of the script.

time.sleep(2)

饼干在美丽的圈子中的问题

大姐,你呐 2025-02-10 19:16:44

vimagescale _*功能刻度适合目的地,因此,如果源和目的地的比率不同,纵横比将更改。

Vimage提供仿射变换操作(支持背景颜色!)。 Take a look at https://developer.apple.com/documentation/accelerate/applying_geometric_transforms_to_images有关更多信息。最后一个示例,将复杂的仿射变换应用于Vimage Buffer ,完全需要您需要的工作(您只需要删除旋转步骤)即可。

The vImageScale_* functions scale to fit the destination, so the aspect ratio will change if the source and destination are different ratios.

vImage provides affine transform operations (with support for a background colour!). Take a look at https://developer.apple.com/documentation/accelerate/applying_geometric_transforms_to_images for more information. The final example, Apply a Complex Affine Transform to a vImage Buffer, does exactly what you need (you just need to remove the rotate step).

将cvpixelbuffer安装到具有调整大小和纵横比节省大小的平方图像中

大姐,你呐 2025-02-10 12:08:21

使用共享的prefs并在完成后清除它们

Use shared prefs and clear them when you are done

从另一个活动中单击时添加到阵列列表中

大姐,你呐 2025-02-10 05:21:45

您可以使用一个包含这些值的对象的单个状态。

例如:

const [loadingStates, setLoadingStates] = useState({
    loading: true,
    loadingSave: false,
    loadingDelete: false,
    loadingDownload: false,
});

要更改值,您可以使用:

setLoadingStates(prevObject => {
    return {
        ...prevObject,
        loading: false,
    }
});

希望这有帮助

You can use a single state with an object that contains these values.

for example:

const [loadingStates, setLoadingStates] = useState({
    loading: true,
    loadingSave: false,
    loadingDelete: false,
    loadingDownload: false,
});

for changing the values, you can use:

setLoadingStates(prevObject => {
    return {
        ...prevObject,
        loading: false,
    }
});

Hope this helps

用ReactJ中的多个切换状态清理代码

大姐,你呐 2025-02-09 17:39:29

使用Explode()或preg_split()函数将字符串与给定定界线分开

// Use preg_split() function 
$string = "123,456,78,000";  
$str_arr = preg_split ("/\,/", $string);  
print_r($str_arr); 
  
// use of explode 
$string = "123,46,78,000"; 
$str_arr = explode (",", $string);  
print_r($str_arr); 

Use explode() or preg_split() function to split the string in php with given delimiter

// Use preg_split() function 
$string = "123,456,78,000";  
$str_arr = preg_split ("/\,/", $string);  
print_r($str_arr); 
  
// use of explode 
$string = "123,46,78,000"; 
$str_arr = explode (",", $string);  
print_r($str_arr); 

将逗号限制的字符串分为数组?

大姐,你呐 2025-02-09 02:47:39

从状态栏(右下区域)中选择正确的Python解释器。如果错误仍然存​​在,请重新启动与代码。

Choose the correct python interpreter from the status bar (lower right area). If the error still exists, restart VS Code.

VSC可以找到一个Python模块,该模块完美地在终端和Pycharm中工作

大姐,你呐 2025-02-08 18:35:00

首先,您不应该在公共论坛中发布应用程序秘密。其次,您可以发布index.html文件吗?可能会错误地加载JS和CSS文件。第三,您可以从一行中的软件包导入默认和类导出。更改

import express from 'express';
import {Request,Response} from 'express';

import express, { Request, Response } from 'express';

First things first, you shouldn't post the app secret in a public forum. Second, can you post your index.html file? Chances are it incorrectly loads the JS and CSS files. Third, you can import default and class exports from a package in one line. Change

import express from 'express';
import {Request,Response} from 'express';

to

import express, { Request, Response } from 'express';

Node.js Express无法获得CSS和JS文件

大姐,你呐 2025-02-07 11:06:32

这个问题确实是在无上下文解析之间尴尬的荒原,这太确切了,无法处理非结构化的话语,而自然语言解析(据我了解,这并不是为了利用微妙的印刷品而设计的。线索。

我的建议,就其价值而言,您使用临时正则表达式的集合来捕获印刷样式和样板短语。 (“一篇论文被列出并命令躺在房子的桌子上。”)这就是我几十年前尝试与加拿大同等学历做这样的事情时所做的(在佩尔是状态的那一天艺术),尽管需要进行一定量的手动干预,但它主要起作用。 (我的风格是使用理智检查来检测案件不当,并记录下来以允许将来改进。)所有工作的工作量取决于您需要结果的精确度。

如果您可以访问足够的计算资源,则很有可能建立一个可以做到合理工作的机器学习模型。但是,除非您可以忍受错误,否则您仍然需要进行大量验证和重新校准。

This problem is indeed in an awkward wasteland between context-free parsing, which is far too precise to handle unstructured discourse, and natural language parsing, which (as I understand the current state of the art) is not designed to take advantage of subtle printed clues.

My recommendation, for what it's worth, is that you use a collection of ad hoc regular expressions to attempt to capture the printed style and the boilerplate phrases. ("A paper was tabled and ordered to lie upon the table of the house.") That's what I did when I tried to do something like this a couple of decades ago with the Canadian equivalent (in the days in which Perl was state of the art), and it mostly worked, although a certain amount of manual intervention was required. (My style is to use sanity checks to try to detect cases which are mishandled and log them to allow future improvements.) How much work all that is will depend on how precise you need the results to be.

It's quite possible that you could build a machine learning model which did a reasonable job, if you have access to enough computational resources. But you'll still need to do a lot of verification and recalibration, unless you can tolerate errors.

语法解析议会辩论?

大姐,你呐 2025-02-07 07:20:14

box 组件中添加 component prop以求解 typescript mui box 中的错误。对于组件 Prop,将输入作为 div或span

    <Box component="div">
       ----
       --
    </Box>

add the component prop inside the box component to solve the typescript error in the mui box. For the component prop, give the input as div or span

    <Box component="div">
       ----
       --
    </Box>

DevOps SpoteScript构建问题与材料UI盒元素

大姐,你呐 2025-02-06 12:27:10

技术问题

循环中的第一行不会返回一个价格作为整数,而是整个价格列表。此 dictionary1 [“ Price”] 给您 [55,100,25]

逻辑问题

数据结构

我认为您误解了字典是如何工作的。在您的情况下,最好使用具有价格为价值的结构,名称是钥匙的词典。

better_dict = {
    'a': 55,
    'b': 100,
    'c': 25}

在下面的解决方案代码中,我通过 dict(zip(...))将您的dict转换为该表单。

当您用循环的迭代字典上

的字典上迭代您,您只会获得键而不是值。在我的示例中,您有键 ['a','b','c'] 。当您想访问字典中的值时,您必须在循环内使用键。

解决方案

该解决方案试图尽可能少地修改代码。

#!/usr/bin/python3
dictionary1 = {
  "name": ["a", "b", "c"],
  "price": [55, 100, 25]
}

# transform your dict into an easier structure
better_dict = dict(zip(dictionary1["name"], dictionary1["price"]))
# result --> {'a': 55, 'b': 100, 'c': 25}

highest_price = 0
winner = ""

for name in better_dict:  # --> ['a', 'b', 'c']
    # get the value by key/name
    bid_amount = better_dict[name]
    if bid_amount > highest_price:
        highest_price = bid_amount
        winner = name  # use the key as name

print(f"the winner is: {winner}. With {highest_price}")

替代解决方案

,您可以使用另一种方法,而无需为循环使用。它还使用转换的数据结构。

#!/usr/bin/python3
dictionary1 = {
  "name": ["a", "b", "c"],
  "price": [55, 100, 25]
}

better_dict = dict(zip(dictionary1["name"], dictionary1["price"]))
# result --> {'a': 55, 'b': 100, 'c': 25}

# Find key with highest price
winner = sorted(better_dict, key=lambda k: better_dict[k])[-1]
# Get highest price by winners name
highest_price = better_dict[winner]

print(f"the winner is: {winner}. With {highest_price}")

我将尝试为您分解 Winner = 行。 排序(better_dict)(没有 key = !)将返回字典的键(名称)。但是您想要这些价值。因此 key = lambda k:better_dict [k] 告诉 sorted()使用 lambda 函数,该功能返回由元素索引的值键 k 。因为 sorted()默认情况下使用升序(最低价格到最高价格)订单,所以我们使用返回列表的最后一个元素以获取最高价格的名称。您可以通过 [ - 1] 访问列表的最后一个元素。

Technical problem

This first line in your for loop doesn't return one price as an integer but the whole price list. This dictionary1["price"] gives you [55, 100, 25].

Logical problem

Data structure

I think you misunderstood how a dictionary work. In your case it seems the best to use a dictionary with a structure where the prices are the values and the names are the keys.

better_dict = {
    'a': 55,
    'b': 100,
    'c': 25}

In the solution code below I transform your dict via dict(zip(...)) into that form.

Iterate over a dictionary

When you iterate over a dictionary with a for loop you only get the keys not the values. In my example you have the keys ['a', 'b', 'c']. When you want to access the values in a dictionary you have to use the key inside the loop.

Solution

This solutions tries to modify your code as less as possible.

#!/usr/bin/python3
dictionary1 = {
  "name": ["a", "b", "c"],
  "price": [55, 100, 25]
}

# transform your dict into an easier structure
better_dict = dict(zip(dictionary1["name"], dictionary1["price"]))
# result --> {'a': 55, 'b': 100, 'c': 25}

highest_price = 0
winner = ""

for name in better_dict:  # --> ['a', 'b', 'c']
    # get the value by key/name
    bid_amount = better_dict[name]
    if bid_amount > highest_price:
        highest_price = bid_amount
        winner = name  # use the key as name

print(f"the winner is: {winner}. With {highest_price}")

Alternative solution

Here you have an alternative approach without using a for loop. It also uses the transformed data structure.

#!/usr/bin/python3
dictionary1 = {
  "name": ["a", "b", "c"],
  "price": [55, 100, 25]
}

better_dict = dict(zip(dictionary1["name"], dictionary1["price"]))
# result --> {'a': 55, 'b': 100, 'c': 25}

# Find key with highest price
winner = sorted(better_dict, key=lambda k: better_dict[k])[-1]
# Get highest price by winners name
highest_price = better_dict[winner]

print(f"the winner is: {winner}. With {highest_price}")

I will try to break down the winner = line for you. sorted(better_dict) (without key=!) would return the keys (names) of the dictionary. But you want the values. So key=lambda k: better_dict[k] tell the sorted() to use the lambda function that returns the value of an element indexed by a key k. Because sorted() use ascending (lowest to highest price) order by default we use the last element of the returned list to get the name with the highest price. You can access the last element of a list via [-1].

python词典中的循环问题

大姐,你呐 2025-02-06 03:17:08

基本上, docs.data ['...'] 可以是 null ,但 text 必需 non-null 代码>字符串,因此,如果 docs.data ['...'] null会导致错误。

要解决它,请在其上添加null-Check/default-value。

例子:

// Text(docs.data['제목'])
-> Text(docs.data['제목'] ?? 'your default value')

Basically, docs.data['...'] can be null but Text required non-null String, so in case docs.data['...'] null it will cause error.

To solve it, add null-check/default-value to it.

Example:

// Text(docs.data['제목'])
-> Text(docs.data['제목'] ?? 'your default value')

颤音 - 阵列的2个特定元素的错误

大姐,你呐 2025-02-06 02:26:17

通常,即使在同一核心上运行,在单独的线程上运行的网络和其他I/O密集型代码也不会干扰其他灾难性。那是因为任何一个线程都可能花费时间被封锁,等待一些IO操作完成,而其他线程则可以自由执行并做一些有用的事情。从这个意义上讲,您在核心之间进行仔细的线程分裂并没有太大影响。即使与WiFi驱动程序在相同的核心上运行,LED闪烁的眨眼都不会注意到。当然,可能会有一些时机问题可能会引起非常敏感的实时过程问题 - 也许在某个地方延迟了约10毫秒,但是您不会用肉眼闪烁的LED看到这一点。

看来您的具体问题是 blynk.run()没有Internet连接时阻止: https://community.particle.io/t/blynk-blocking-code-code-code-if-no-no-no-no-connection-to-no-connection-to-no-connection- wifi-or-cloud/36039 。反过来,这导致LED被阻止,直到恢复连接并 blynk.run()退出为止。这与多线程无关,这只是图书馆的不良设计。

Usually networking and other I/O-intensive code running on separate threads does not interfere with other catastrophically, even if running on the same core. That's because any one thread is likely spending its time blocked, waiting for some IO operation to complete, while other threads are free to execute and do something useful. In this sense your careful division of threads among cores does not have much effect. You wouldn't notice any irregularities in the LED's blinking even if running on the same core as the WiFi driver. Sure, there might be timing issues which could cause problems with very sensitive real time processes - maybe a ~10 ms delay somewhere but you wouldn't see this from blinking LEDs with a naked eye.

It seems that your specific problem here is that Blynk.run() blocks when there's no Internet connection: https://community.particle.io/t/blynk-blocking-code-if-no-connection-to-wifi-or-cloud/36039. This in turn causes the LED to be blocked until the connection is restored and Blynk.run() exits. That's not related to multithreading, that's just bad design of the library.

core0封锁代码从core1到ESP32运行(不应该同时运行两个代码?)

大姐,你呐 2025-02-05 06:30:53

我不知道石榴,但是如果可以的话,请使用pyagrum,

import pyAgrum as gum
import pandas as pd
import pyAgrum.lib.notebook as gnb 

df = pd.DataFrame({'A':[0,0,0,1,0], 'B':[0,0,1,0,0], 'C':[1,1,0,0,1], 'D':[0,1,0,1,1]})
gum.BNLearner(df).useAprioriSmoothing(1e-5).useScoreLog2Likelihood().learnBN()

它在jupyter笔记本中返回:

有关博学的BN的更多信息,

bn=gum.BNLearner(df).useAprioriSmoothing(1e-).useScoreLog2Likelihood().learnBN()
gnb.sideBySide(bn,gnb.getInference(bn))
gnb.sideBySide(*[bn.cpt(i) for i in bn.nodes()])

I do not know for Pomegranate, but if I may, using pyAgrum,

import pyAgrum as gum
import pandas as pd
import pyAgrum.lib.notebook as gnb 

df = pd.DataFrame({'A':[0,0,0,1,0], 'B':[0,0,1,0,0], 'C':[1,1,0,0,1], 'D':[0,1,0,1,1]})
gum.BNLearner(df).useAprioriSmoothing(1e-5).useScoreLog2Likelihood().learnBN()

which returns in a jupyter notebook :

enter image description here

For more information on the learned BN,

bn=gum.BNLearner(df).useAprioriSmoothing(1e-).useScoreLog2Likelihood().learnBN()
gnb.sideBySide(bn,gnb.getInference(bn))
gnb.sideBySide(*[bn.cpt(i) for i in bn.nodes()])

enter image description here

如何可视化石榴构建的贝叶斯网络模型

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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