绮筵

文章 评论 浏览 30

绮筵 2025-02-21 00:49:38

使用别名:

UPDATE t
   SET t.col1 = o.col1
  FROM table1 AS t
         INNER JOIN 
       table2 AS o 
         ON t.id = o.id

Using alias:

UPDATE t
   SET t.col1 = o.col1
  FROM table1 AS t
         INNER JOIN 
       table2 AS o 
         ON t.id = o.id

如何从SQL Server中的选择中更新?

绮筵 2025-02-20 19:52:50

您已经使用 @Autowired @bean 等等,因此您绝对需要 spring-core artifact。

但是,对于这些类型的示例,例如您在问题中提到的示例(仅使用 main 方法的简单命令行Java程序),Spring创建了另一种方法。

阅读本文如何使用Spring的功能创建一个简单的命令线程序可用的。

重要的是要注意。属性 spring.main.web-application-type = none 的使用是必须的,因此当执行JAR文件时,Spring不会启动任何嵌入式Web服务器。

You already use @Autowired, @Bean and some more, so you definitely need spring-core artifact.

But for those type of examples like what you mention in your question (a simple command line java program with just a main method), spring has created another approach.

Read this article on how to creat a simple command line program with features of spring available.

Important to note. The use of property spring.main.web-application-type=NONE is a must, so that spring does not start any embedded web server like tomcat when the jar file is executed.

如何使用Spring-data-redis没有弹簧靴Java项目

绮筵 2025-02-20 16:20:41

我可以成功运行代码,而无需错误的PF屏幕截图。也许您可以检查变形金刚版本吗?

我有一个使用Transformers Model/Tokenizers功能的COLAB笔记本电脑,也许您可​​以直接使用它们。
https://colab.research.google.com/drive/12gwdua-fs7h31hic5frzavt6ofyelwux?usp = sharing

我希望这会有所帮助!

I can run the code successfully without an error PF screenshot. Maybe can you check with your transformers version?

I have a colab notebook using transformers model/tokenizers functions directly maybe you can use them directly.
https://colab.research.google.com/drive/12gwdua-Fs7H31HIc5frzavT6ofyeLWux?usp=sharing

I hope this helps, Thanks!

enter image description here

叛军:端到端语言的关系提取

绮筵 2025-02-20 00:03:25

以下是做您提出问题的两种方法,一种是使用大熊猫,另一种使用numpy(更新)在有关binning的评论中反映了有关binning的澄清,以基于连续分组的 bin 值):

res = df.assign(bin_index = (df.bin != df.bin.shift()).cumsum())

dfAggs = res[['butter', 'bin', 'bin_index']].groupby(['bin', 'bin_index']).agg([min, max])
dfAggs.columns = dfAggs.columns.droplevel()
res = res.join(dfAggs, on=['bin', 'bin_index']).drop(columns='bin_index')
print("", "pandas:", res, sep="\n")

a = df.copy().to_numpy()
print("", "input as numpy 2d array", a, sep="\n")
bin_index = a[:,2:3] != np.concatenate((np.full((1, 1), np.NaN), a[:-1,2:3]), axis = 0)
bin_index = np.cumsum(bin_index)
bins = np.unique(bin_index)
aggs = np.empty((a.shape[0], 2))
for b in bins:
    mask = bin_index==b
    aggs[mask, :] = (a[mask, 1].min(), a[mask, 1].max())
res = np.concatenate((a, aggs), axis=1)
print("", "numpy:", res, sep="\n")

输出:

input as pandas dataframe
                         time    butter  bin
0   2022-07-04 17:33:45+00:00  1.041967    3
1   2022-07-04 17:34:00+00:00  1.041967    4
2   2022-07-04 17:34:15+00:00  1.041966    4
3   2022-07-04 17:34:30+00:00  1.041967    4
4   2022-07-04 17:34:45+00:00  1.041968    4
5   2022-07-04 17:35:00+00:00  1.041969    4
6   2022-07-04 17:35:15+00:00  1.041971    4
7   2022-07-04 17:35:30+00:00  1.041973    4
8   2022-07-04 17:35:45+00:00  1.041975    4
9   2022-07-04 17:36:00+00:00  1.041977    5
10  2022-07-04 17:36:15+00:00  1.041979    5
11  2022-07-04 17:36:30+00:00  1.041981    5
12  2022-07-04 17:36:45+00:00  1.041983    5
13  2022-07-04 17:37:00+00:00  1.041985    5
14  2022-07-04 17:37:15+00:00  1.041986    6
15  2022-07-04 17:37:30+00:00  1.041987    6
16  2022-07-04 17:37:45+00:00  1.041988    6
17  2022-07-04 17:38:00+00:00  1.041989    6
18  2022-07-04 17:38:15+00:00  1.041990    4
19  2022-07-04 17:38:30+00:00  1.041995    4

pandas:
                         time    butter  bin       min       max
0   2022-07-04 17:33:45+00:00  1.041967    3  1.041967  1.041967
1   2022-07-04 17:34:00+00:00  1.041967    4  1.041966  1.041975
2   2022-07-04 17:34:15+00:00  1.041966    4  1.041966  1.041975
3   2022-07-04 17:34:30+00:00  1.041967    4  1.041966  1.041975
4   2022-07-04 17:34:45+00:00  1.041968    4  1.041966  1.041975
5   2022-07-04 17:35:00+00:00  1.041969    4  1.041966  1.041975
6   2022-07-04 17:35:15+00:00  1.041971    4  1.041966  1.041975
7   2022-07-04 17:35:30+00:00  1.041973    4  1.041966  1.041975
8   2022-07-04 17:35:45+00:00  1.041975    4  1.041966  1.041975
9   2022-07-04 17:36:00+00:00  1.041977    5  1.041977  1.041985
10  2022-07-04 17:36:15+00:00  1.041979    5  1.041977  1.041985
11  2022-07-04 17:36:30+00:00  1.041981    5  1.041977  1.041985
12  2022-07-04 17:36:45+00:00  1.041983    5  1.041977  1.041985
13  2022-07-04 17:37:00+00:00  1.041985    5  1.041977  1.041985
14  2022-07-04 17:37:15+00:00  1.041986    6  1.041986  1.041989
15  2022-07-04 17:37:30+00:00  1.041987    6  1.041986  1.041989
16  2022-07-04 17:37:45+00:00  1.041988    6  1.041986  1.041989
17  2022-07-04 17:38:00+00:00  1.041989    6  1.041986  1.041989
18  2022-07-04 17:38:15+00:00  1.041990    4  1.041990  1.041995
19  2022-07-04 17:38:30+00:00  1.041995    4  1.041990  1.041995

input as numpy 2d array
[['2022-07-04 17:33:45+00:00' 1.041967 3]
 ['2022-07-04 17:34:00+00:00' 1.041967 4]
 ['2022-07-04 17:34:15+00:00' 1.041966 4]
 ['2022-07-04 17:34:30+00:00' 1.041967 4]
 ['2022-07-04 17:34:45+00:00' 1.041968 4]
 ['2022-07-04 17:35:00+00:00' 1.041969 4]
 ['2022-07-04 17:35:15+00:00' 1.041971 4]
 ['2022-07-04 17:35:30+00:00' 1.041973 4]
 ['2022-07-04 17:35:45+00:00' 1.041975 4]
 ['2022-07-04 17:36:00+00:00' 1.041977 5]
 ['2022-07-04 17:36:15+00:00' 1.041979 5]
 ['2022-07-04 17:36:30+00:00' 1.041981 5]
 ['2022-07-04 17:36:45+00:00' 1.041983 5]
 ['2022-07-04 17:37:00+00:00' 1.041985 5]
 ['2022-07-04 17:37:15+00:00' 1.041986 6]
 ['2022-07-04 17:37:30+00:00' 1.041987 6]
 ['2022-07-04 17:37:45+00:00' 1.041988 6]
 ['2022-07-04 17:38:00+00:00' 1.041989 6]
 ['2022-07-04 17:38:15+00:00' 1.04199 4]
 ['2022-07-04 17:38:30+00:00' 1.041995 4]]

numpy:
[['2022-07-04 17:33:45+00:00' 1.041967 3 1.041967 1.041967]
 ['2022-07-04 17:34:00+00:00' 1.041967 4 1.041966 1.041975]
 ['2022-07-04 17:34:15+00:00' 1.041966 4 1.041966 1.041975]
 ['2022-07-04 17:34:30+00:00' 1.041967 4 1.041966 1.041975]
 ['2022-07-04 17:34:45+00:00' 1.041968 4 1.041966 1.041975]
 ['2022-07-04 17:35:00+00:00' 1.041969 4 1.041966 1.041975]
 ['2022-07-04 17:35:15+00:00' 1.041971 4 1.041966 1.041975]
 ['2022-07-04 17:35:30+00:00' 1.041973 4 1.041966 1.041975]
 ['2022-07-04 17:35:45+00:00' 1.041975 4 1.041966 1.041975]
 ['2022-07-04 17:36:00+00:00' 1.041977 5 1.041977 1.041985]
 ['2022-07-04 17:36:15+00:00' 1.041979 5 1.041977 1.041985]
 ['2022-07-04 17:36:30+00:00' 1.041981 5 1.041977 1.041985]
 ['2022-07-04 17:36:45+00:00' 1.041983 5 1.041977 1.041985]
 ['2022-07-04 17:37:00+00:00' 1.041985 5 1.041977 1.041985]
 ['2022-07-04 17:37:15+00:00' 1.041986 6 1.041986 1.041989]
 ['2022-07-04 17:37:30+00:00' 1.041987 6 1.041986 1.041989]
 ['2022-07-04 17:37:45+00:00' 1.041988 6 1.041986 1.041989]
 ['2022-07-04 17:38:00+00:00' 1.041989 6 1.041986 1.041989]
 ['2022-07-04 17:38:15+00:00' 1.04199 4 1.04199 1.041995]
 ['2022-07-04 17:38:30+00:00' 1.041995 4 1.04199 1.041995]]

熊猫说明:

  • 一个ID值
  • 创建 bin_index 列,该列检测 bin 中的变化,并为每个这样的行使用 dataframe.groupby()基于 bin_index
  • 使用 data> dataframe 。 min Max 列到原始数据框架。

numpy说明:

  • 创建 bin_index 数组,该数组在 bin 中检测变化,并为每个这样的行增量一个ID值
  • 准备 aggs 作为阵列 A.形状[0],2 用于接收 min max 相应 bin 的列中的输入中的值Array A
  • 使用布尔掩码对 bin_index 中的每个唯一 bin 值使用 butter a 的列,并将这两个值放在 aggs 的列中,这些行
  • 使用 numpy.concatenate() to to胶水 a aggs 水平合在一起。

Here are two ways to do what your question asks, one using pandas and the other using numpy (UPDATED to reflect OP's clarification in comments regarding binning to be on the basis of contiguously grouped bin values):

res = df.assign(bin_index = (df.bin != df.bin.shift()).cumsum())

dfAggs = res[['butter', 'bin', 'bin_index']].groupby(['bin', 'bin_index']).agg([min, max])
dfAggs.columns = dfAggs.columns.droplevel()
res = res.join(dfAggs, on=['bin', 'bin_index']).drop(columns='bin_index')
print("", "pandas:", res, sep="\n")

a = df.copy().to_numpy()
print("", "input as numpy 2d array", a, sep="\n")
bin_index = a[:,2:3] != np.concatenate((np.full((1, 1), np.NaN), a[:-1,2:3]), axis = 0)
bin_index = np.cumsum(bin_index)
bins = np.unique(bin_index)
aggs = np.empty((a.shape[0], 2))
for b in bins:
    mask = bin_index==b
    aggs[mask, :] = (a[mask, 1].min(), a[mask, 1].max())
res = np.concatenate((a, aggs), axis=1)
print("", "numpy:", res, sep="\n")

Output:

input as pandas dataframe
                         time    butter  bin
0   2022-07-04 17:33:45+00:00  1.041967    3
1   2022-07-04 17:34:00+00:00  1.041967    4
2   2022-07-04 17:34:15+00:00  1.041966    4
3   2022-07-04 17:34:30+00:00  1.041967    4
4   2022-07-04 17:34:45+00:00  1.041968    4
5   2022-07-04 17:35:00+00:00  1.041969    4
6   2022-07-04 17:35:15+00:00  1.041971    4
7   2022-07-04 17:35:30+00:00  1.041973    4
8   2022-07-04 17:35:45+00:00  1.041975    4
9   2022-07-04 17:36:00+00:00  1.041977    5
10  2022-07-04 17:36:15+00:00  1.041979    5
11  2022-07-04 17:36:30+00:00  1.041981    5
12  2022-07-04 17:36:45+00:00  1.041983    5
13  2022-07-04 17:37:00+00:00  1.041985    5
14  2022-07-04 17:37:15+00:00  1.041986    6
15  2022-07-04 17:37:30+00:00  1.041987    6
16  2022-07-04 17:37:45+00:00  1.041988    6
17  2022-07-04 17:38:00+00:00  1.041989    6
18  2022-07-04 17:38:15+00:00  1.041990    4
19  2022-07-04 17:38:30+00:00  1.041995    4

pandas:
                         time    butter  bin       min       max
0   2022-07-04 17:33:45+00:00  1.041967    3  1.041967  1.041967
1   2022-07-04 17:34:00+00:00  1.041967    4  1.041966  1.041975
2   2022-07-04 17:34:15+00:00  1.041966    4  1.041966  1.041975
3   2022-07-04 17:34:30+00:00  1.041967    4  1.041966  1.041975
4   2022-07-04 17:34:45+00:00  1.041968    4  1.041966  1.041975
5   2022-07-04 17:35:00+00:00  1.041969    4  1.041966  1.041975
6   2022-07-04 17:35:15+00:00  1.041971    4  1.041966  1.041975
7   2022-07-04 17:35:30+00:00  1.041973    4  1.041966  1.041975
8   2022-07-04 17:35:45+00:00  1.041975    4  1.041966  1.041975
9   2022-07-04 17:36:00+00:00  1.041977    5  1.041977  1.041985
10  2022-07-04 17:36:15+00:00  1.041979    5  1.041977  1.041985
11  2022-07-04 17:36:30+00:00  1.041981    5  1.041977  1.041985
12  2022-07-04 17:36:45+00:00  1.041983    5  1.041977  1.041985
13  2022-07-04 17:37:00+00:00  1.041985    5  1.041977  1.041985
14  2022-07-04 17:37:15+00:00  1.041986    6  1.041986  1.041989
15  2022-07-04 17:37:30+00:00  1.041987    6  1.041986  1.041989
16  2022-07-04 17:37:45+00:00  1.041988    6  1.041986  1.041989
17  2022-07-04 17:38:00+00:00  1.041989    6  1.041986  1.041989
18  2022-07-04 17:38:15+00:00  1.041990    4  1.041990  1.041995
19  2022-07-04 17:38:30+00:00  1.041995    4  1.041990  1.041995

input as numpy 2d array
[['2022-07-04 17:33:45+00:00' 1.041967 3]
 ['2022-07-04 17:34:00+00:00' 1.041967 4]
 ['2022-07-04 17:34:15+00:00' 1.041966 4]
 ['2022-07-04 17:34:30+00:00' 1.041967 4]
 ['2022-07-04 17:34:45+00:00' 1.041968 4]
 ['2022-07-04 17:35:00+00:00' 1.041969 4]
 ['2022-07-04 17:35:15+00:00' 1.041971 4]
 ['2022-07-04 17:35:30+00:00' 1.041973 4]
 ['2022-07-04 17:35:45+00:00' 1.041975 4]
 ['2022-07-04 17:36:00+00:00' 1.041977 5]
 ['2022-07-04 17:36:15+00:00' 1.041979 5]
 ['2022-07-04 17:36:30+00:00' 1.041981 5]
 ['2022-07-04 17:36:45+00:00' 1.041983 5]
 ['2022-07-04 17:37:00+00:00' 1.041985 5]
 ['2022-07-04 17:37:15+00:00' 1.041986 6]
 ['2022-07-04 17:37:30+00:00' 1.041987 6]
 ['2022-07-04 17:37:45+00:00' 1.041988 6]
 ['2022-07-04 17:38:00+00:00' 1.041989 6]
 ['2022-07-04 17:38:15+00:00' 1.04199 4]
 ['2022-07-04 17:38:30+00:00' 1.041995 4]]

numpy:
[['2022-07-04 17:33:45+00:00' 1.041967 3 1.041967 1.041967]
 ['2022-07-04 17:34:00+00:00' 1.041967 4 1.041966 1.041975]
 ['2022-07-04 17:34:15+00:00' 1.041966 4 1.041966 1.041975]
 ['2022-07-04 17:34:30+00:00' 1.041967 4 1.041966 1.041975]
 ['2022-07-04 17:34:45+00:00' 1.041968 4 1.041966 1.041975]
 ['2022-07-04 17:35:00+00:00' 1.041969 4 1.041966 1.041975]
 ['2022-07-04 17:35:15+00:00' 1.041971 4 1.041966 1.041975]
 ['2022-07-04 17:35:30+00:00' 1.041973 4 1.041966 1.041975]
 ['2022-07-04 17:35:45+00:00' 1.041975 4 1.041966 1.041975]
 ['2022-07-04 17:36:00+00:00' 1.041977 5 1.041977 1.041985]
 ['2022-07-04 17:36:15+00:00' 1.041979 5 1.041977 1.041985]
 ['2022-07-04 17:36:30+00:00' 1.041981 5 1.041977 1.041985]
 ['2022-07-04 17:36:45+00:00' 1.041983 5 1.041977 1.041985]
 ['2022-07-04 17:37:00+00:00' 1.041985 5 1.041977 1.041985]
 ['2022-07-04 17:37:15+00:00' 1.041986 6 1.041986 1.041989]
 ['2022-07-04 17:37:30+00:00' 1.041987 6 1.041986 1.041989]
 ['2022-07-04 17:37:45+00:00' 1.041988 6 1.041986 1.041989]
 ['2022-07-04 17:38:00+00:00' 1.041989 6 1.041986 1.041989]
 ['2022-07-04 17:38:15+00:00' 1.04199 4 1.04199 1.041995]
 ['2022-07-04 17:38:30+00:00' 1.041995 4 1.04199 1.041995]]

Pandas explanation:

  • Create bin_index column which detects changes in bin and increments an id value for each such row
  • Use DataFrame.groupby() to perform the aggregation (min, max) based on bin_index
  • Use DataFrame.join() (with preprocessing of the aggregation dataframe aggs to remove the level of its MultiIndex named butter) to add min and max columns to the original dataframe.

Numpy explanation:

  • Create bin_index array which detects changes in bin and increments an id value for each such row
  • Prepare aggs as an array with shape a.shape[0], 2 for receiving min and max columns for the corresponding bin value in the input array a
  • Use a boolean mask for each unique bin value in bin_index to perform aggregation on the corresponding rows of the butter column of a and to place these two values in the columns of aggs for these same rows
  • Use numpy.concatenate() to glue a and aggs together horizontally.

python本地最小/最大垃圾箱没有更改

绮筵 2025-02-19 10:58:26

如果您的计算机上有一个预先存在的代码库(我认为是这种情况),并且您需要将此代码库“上传”到GitHub,则您需要执行一些操作:

  1. 在上github。如果您不熟悉命令行,建议您在Web UI上进行。您应该按照 @ben答案中的链接:在上github

  2. 初始化机器上的本地存储库。为此,您应该将终端和 cd 启动到代码库的文件夹中。

      CD/PATH/TO/您的/代码
    git init
     
  3. 将您的本地存储库与GitHub上的远程存储库联系起来。
    转到您新创建的回购,复制链接,如下图所示:

    “

    确保您要复制 https url。 ssh 类型URL需要更多的配置,并且当您更愿意使用 git ssh tooling时,可以执行此操作。

    然后运行以下命令:

      git Remote添加Origin<您的回购URL>
     

    您可以在此处阅读有关Git Repo,Remote Repo和local Repo的更多信息

  4. 提交并推动您的代码。

      git commit -a -m“初始提交”
    git推出原点
    #您将需要输入您的用户名和密码
     

    github要求如果您在命令行中推动代码,则需要使用个人访问令牌。您可以参考此链接为自己创建PAT。

下一步您应该更多地了解 git 工具。我建议阅读 atlassian的git tutorial ,或=“ https://git-scm.com/book/en/v2” rel =“ nofollow noreferrer”> git书

If you have a pre-existing codebase on your machine (which I assume is the case), and you need to "upload" this codebase to GitHub, then you would need to perform a few actions:

  1. Create a new repo on GitHub. If you are not familiar with the command line, I suggest doing it on the Web UI. You should follow the link in @Ben's answer: Create a repo on GitHub

  2. Initialize a local repo on your machine. To do this, you should fire up a terminal and cd into the folder of your codebase.

    cd /path/to/your/code
    git init
    
  3. Link up your local repo with the remote repo on GitHub.
    Go to your newly created repo, copy the link as shown in the picture below:

    Repo url

    Ensure you are copying the https URL. The ssh type URL requires a little bit more configurations, and you can do this when you are more comfortable with working with git and ssh tooling.

    Then run the following command:

    git remote add origin <your repo url>
    

    You can read more about git repo, remote repo and local repo here

  4. Commit and push your code.

    git commit -a -m "initial commit"
    git push origin main
    # you will be required to enter your username and password
    

    GitHub requires you to use a Personal Access Token if you are pushing your code in the command line. You can refer to this link to create a PAT for yourself.

The next step for you should be learning more about the git tooling. I would recommend reading Atlassian's git tutorial, or the Git book

我如何创建一个新的存储库并将其上传到GitHub

绮筵 2025-02-19 07:16:50

It seems that in okhttp3, it's using proxy() for the OkHttpClient.Builder. proxy() has the same documentation as setProxy() in older okhttp.

Here are some examples using proxy().

okhttp3.okhttpclient.setproxy找不到符号

绮筵 2025-02-18 17:36:32

我最终尝试了所有内容,包括禁用缩放,但是对我没有任何帮助。在与另一个项目进行比较之后,我发现显然 flutter Pub 很奇怪,并且使用 1.xx 作为版本约束(即使我通过 Flutter Pub添加)。

更改 pubspec.yaml 中的依赖项为 2.xx 工作:

dependencies:
    ....
    firebase_core: ^2.7.1

请确保您使用的是: https://pub.dev/packages/firebase_core

如果您面临类似的问题,也可以为其他Firebase插件软件包做同样的事情。

I ended up trying everything including disabling minify, however nothing worked for me. After comparing to another project I found out that apparently flutter pub was being weird and was using 1.x.x as the version constraint(even though I was adding the dependency through flutter pub add).

Changing the dependency in pubspec.yaml to 2.x.x worked:

dependencies:
    ....
    firebase_core: ^2.7.1

Please ensure that you are using the correct version from: https://pub.dev/packages/firebase_core.

You can also do the same for other firebase plugin packages if you are facing a similar issue with them.

缺少Pluginexception(缺少Pluginexception(在Channel plugins.flutter.io/firebase_core上找不到用于方法firebase#directizecore的实现)

绮筵 2025-02-18 16:13:37

我们总是可以写入

 z = x xnor y

x,y,x是二进制变量的位置

 z >= 1-x-y
 z <= 1-x+y
 z <= 1+x-y
 z >= x+y-1

。这是严格的(派生为

有时,由于目标(或约束)的工作原理,我们可以放弃&lt; = or&gt; =不平等。

We always can write

 z = x xnor y

as

 z >= 1-x-y
 z <= 1-x+y
 z <= 1+x-y
 z >= x+y-1

where x,y,x are binary variables. This is rigorous (derivation is here) and tight (we can even relax z to be continuous between 0 and 1).

Sometimes we can drop the <= or >= inequalities because of how the objective (or constraint) works.

在PYOMO中建模Xnor

绮筵 2025-02-18 10:34:56

您可以解决此转换的方式之一,然后创建数据框架。
示例示例:

import pandas as pd
import numpy as np

def function(pages=0):
    # Replace this with your logic
    a=list(range(10))
    b=[i*0.9 for i in a]
    c=[i*0.5 for i in a]
    return [a,b,c]

data=np.array(function()).T.tolist()

df=pd.DataFrame(data=data,columns=['A','B','C'])

输出:

In []: df
Out[25]:
     A    B    C
0  0.0  0.0  0.0
1  1.0  0.9  0.5
2  2.0  1.8  1.0
3  3.0  2.7  1.5
4  4.0  3.6  2.0
5  5.0  4.5  2.5
6  6.0  5.4  3.0
7  7.0  6.3  3.5
8  8.0  7.2  4.0
9  9.0  8.1  4.5

One of the way you can address this transpose the output and then create the dataframe.
A sample example:

import pandas as pd
import numpy as np

def function(pages=0):
    # Replace this with your logic
    a=list(range(10))
    b=[i*0.9 for i in a]
    c=[i*0.5 for i in a]
    return [a,b,c]

data=np.array(function()).T.tolist()

df=pd.DataFrame(data=data,columns=['A','B','C'])

Output:

In []: df
Out[25]:
     A    B    C
0  0.0  0.0  0.0
1  1.0  0.9  0.5
2  2.0  1.8  1.0
3  3.0  2.7  1.5
4  4.0  3.6  2.0
5  5.0  4.5  2.5
6  6.0  5.4  3.0
7  7.0  6.3  3.5
8  8.0  7.2  4.0
9  9.0  8.1  4.5

错误:传递的3列,传递的数据有1列(从列表中创建数据框)

绮筵 2025-02-17 16:29:10

尝试将 MAP 函数与结合使用并返回合并的对象。
另外,您可能想将文件内容解析为JSON对象:

const arr1 = JSON.parse(fs.readFileSync('file1.txt', 'utf8'));
console.log(arr1);
const arr2 = JSON.parse(fs.readFileSync('file2.text', 'utf8'));
console.log(arr2);

const merge = (arr1, arr2) => {
  return arr1.map(x => {
    const y = arr2.find(val => val.customerid === x.customerid);
    if (!y) return x;
    return { ...x, ...y }
  })
};

console.log(merge(arr1, arr2));

Try to use the map function in combination with find and return the merged object.
Also, you may wanna parse the file content to a JSON object:

const arr1 = JSON.parse(fs.readFileSync('file1.txt', 'utf8'));
console.log(arr1);
const arr2 = JSON.parse(fs.readFileSync('file2.text', 'utf8'));
console.log(arr2);

const merge = (arr1, arr2) => {
  return arr1.map(x => {
    const y = arr2.find(val => val.customerid === x.customerid);
    if (!y) return x;
    return { ...x, ...y }
  })
};

console.log(merge(arr1, arr2));

两个TXT文件数据如何基于CustomerID获取和合并如何使用Node JS获取两个TXT文件数据?

绮筵 2025-02-17 05:30:53

正如评论中所说,您有一个更改听众倾听所有结果的更改。每当更改结果之一时,将所有结果都添加到您的数组中并将其登录到控制台。
也许更改的侦听器不是您需要的 - 也许您可以在输入所有结果时让用户单击一个按钮,然后在按钮上单击创建数组。
否则,您可以解析数组并检查所有值是否具有长度?

const validArray = !array.some(item => item.length === 0);

(如果您的数组包含一个或多个空字符串的实例,则会返回false,如果您的数组有效。仅在值为True(如果值为true)时,请继续进行下一步)。

还请注意,您的数组是由字符串而不是整数组成的。我不确定这是否是您想要的。

As was said in the comment, you have a change listener listening for changes to all of the results. Any time one of the results is changed, all of them are added to your array and logged to the console.
Maybe a change listener isn't what you need - perhaps you could get the user to click a button when all the results have been entered, then on the button click create the array.
Otherwise, you could parse your array and check that all the values have a length?

const validArray = !array.some(item => item.length === 0);

(will return false if your array contains one or more instances of empty string, or true if your array is valid. Only proceed to the next step if the value is true)

Also note that your array is made up of strings, not integers. I'm not sure if this is what you want.

如何通过ID获取多个输入字段的值

绮筵 2025-02-17 03:00:47

fgets 可用于读取文件的每一行。
使用 strncmp 将行的第一个字符与序列号进行比较。 strncmp 将返回 0 for Match。
在比赛中, sscanf 可以从行中解析字段。 SCANSET %19 [^;]; 最多将扫描19个不是半彩色的字符,然后扫描半彩色。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main ( void)
{
    char matricola[50] = "";
    char line[100] = "";

    printf("insert serial number: \n");
    fgets ( matricola, sizeof matricola, stdin);
    size_t length = strcspn ( matricola, "\n");
    matricola[length] = 0; // remove newline

    FILE *fp=fopen("prova.txt","r");
    if (!fp){
        printf("file doesnt exist\n");
        return -1;
    }

    char (*matrice)[4][20] = NULL;
    size_t rows = 0;

    while ( fgets ( line, sizeof line, fp)) {
        if ( ! strncmp ( line, matricola, length)) {
            char (*temp)[4][20] = NULL;
            if ( NULL == ( temp = realloc ( matrice, sizeof *matrice * ( rows + 1)))) {
                fprintf ( stderr, "realloc problem\n");
                free ( matrice);
                return 1;
            }
            matrice = temp;
            if ( 4 == sscanf ( line, "%19[^;];%19[^;];%19[^;];%19[^\n]"
            , matrice[rows][0]
            , matrice[rows][1]
            , matrice[rows][2]
            , matrice[rows][3])) {
                ++rows;
            }
        }

    }

    for ( size_t each = 0; each < rows; ++each) {
        printf ( "%s\n", matrice[each][0]);
        printf ( "%s\n", matrice[each][1]);
        printf ( "%s\n", matrice[each][2]);
        printf ( "%s\n\n", matrice[each][3]);
    }

    free ( matrice);
    return 0;
}

fgets can be used to read each line of the file.
Use strncmp to compare the first characters of the line to the serial number. strncmp will return 0 for a match.
Upon a match, sscanf can parse the fields from the line. The scanset %19[^;]; will scan up to 19 characters that are not a semi-colon, then scan the semi-colon.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main ( void)
{
    char matricola[50] = "";
    char line[100] = "";

    printf("insert serial number: \n");
    fgets ( matricola, sizeof matricola, stdin);
    size_t length = strcspn ( matricola, "\n");
    matricola[length] = 0; // remove newline

    FILE *fp=fopen("prova.txt","r");
    if (!fp){
        printf("file doesnt exist\n");
        return -1;
    }

    char (*matrice)[4][20] = NULL;
    size_t rows = 0;

    while ( fgets ( line, sizeof line, fp)) {
        if ( ! strncmp ( line, matricola, length)) {
            char (*temp)[4][20] = NULL;
            if ( NULL == ( temp = realloc ( matrice, sizeof *matrice * ( rows + 1)))) {
                fprintf ( stderr, "realloc problem\n");
                free ( matrice);
                return 1;
            }
            matrice = temp;
            if ( 4 == sscanf ( line, "%19[^;];%19[^;];%19[^;];%19[^\n]"
            , matrice[rows][0]
            , matrice[rows][1]
            , matrice[rows][2]
            , matrice[rows][3])) {
                ++rows;
            }
        }

    }

    for ( size_t each = 0; each < rows; ++each) {
        printf ( "%s\n", matrice[each][0]);
        printf ( "%s\n", matrice[each][1]);
        printf ( "%s\n", matrice[each][2]);
        printf ( "%s\n\n", matrice[each][3]);
    }

    free ( matrice);
    return 0;
}

使用strtok_r()解析文本文件

绮筵 2025-02-17 01:11:56

Typescript Playground link

type Option = {
  value: any,
  label: any
}

interface Role {
  id: number
  name: string
}

const roles: Role[] = [
  { id: 0, name: "foo" },
  { id: 1, name: "bar" },
  { id: 2, name: "baz" },
]

const result: Option[] = roles
  .map(({ id, name }) => ({ label: id, value: name }));

console.log(result);

Result:

[LOG]: [{
  "label": 0,
  "value": "foo"
}, {
  "label": 1,
  "value": "bar"
}, {
  "label": 2,
  "value": "baz"
}]

Typescript Playground link

type Option = {
  value: any,
  label: any
}

interface Role {
  id: number
  name: string
}

const roles: Role[] = [
  { id: 0, name: "foo" },
  { id: 1, name: "bar" },
  { id: 2, name: "baz" },
]

const result: Option[] = roles
  .map(({ id, name }) => ({ label: id, value: name }));

console.log(result);

Result:

[LOG]: [{
  "label": 0,
  "value": "foo"
}, {
  "label": 1,
  "value": "bar"
}, {
  "label": 2,
  "value": "baz"
}]

还原到类型的TypeScript

绮筵 2025-02-16 18:48:56

它实际上删除了具有按钮的父元素。但这是 td 元素。您想删除 grand parent,所以要做:

el.parentElement.parentElement.remove();

仅查找最近的 tr 元素(在祖先元素中)可能会更容易:

el.closest("tr").remove();

function takeOut(el) {
  el.closest("tr").remove();
}

document.getElementById('myButton').onclick = function() {
  const name = document.getElementById('name').value;
  const date = document.getElementById('date').value;
  const amount = document.getElementById('amount').value;
  const nameTd = '<td>' + name + '</td>';
  const dateTd = '<td>' + date + '</td>';
  const amountTd = '<td>' + '
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Expense Tracker</title>
</head>

<body>
  <h1>Expense Tracker</h1>
  <h3>Add A New Item:</h3>
  <label>Name: <input text="text" id="name"></label><br>
  <label>Date:<input type="date" id="date"></label><br>
  <label>Amount:<input text="text" id="amount"></label><br>
  <button type="button" id="myButton">Add Expense</button>
  <button type="button" id="clearList">Clear List</button>
  <br>
  <br>
  <br>
  <br>
  <br>
  <table border="1">
    <tr>
      <th>Name</th>
      <th>Date</th>
      <th>Amount</th>
      <th>Remove</th>
    </tr>
    <tbody id="table">

    </tbody>
  </table>


  <script src="script2.js"></script>
</body>

</html>

+ amount + '</td>' + '<td>' + '<button id="removeBtn"type="button" onClick="takeOut(this)">X</button></td>'; const tr = '<tr>' + nameTd + dateTd + amountTd + '</tr>'; document.getElementById('table').insertAdjacentHTML('beforeend', tr); document.getElementById('clearList').onclick = function() { const cl = document.getElementById('table'); while (cl.hasChildNodes()) { cl.removeChild(cl.firstChild); } } document.getElementById('name').value = ''; document.getElementById('amount').value = ''; document.getElementById('date').value = ''; }

It actually removes the parent element that has the button. But that is a td element. You want to delete the grandparent, so do:

el.parentElement.parentElement.remove();

It may be easier to just look for the closest tr element (among the ancestor elements):

el.closest("tr").remove();

function takeOut(el) {
  el.closest("tr").remove();
}

document.getElementById('myButton').onclick = function() {
  const name = document.getElementById('name').value;
  const date = document.getElementById('date').value;
  const amount = document.getElementById('amount').value;
  const nameTd = '<td>' + name + '</td>';
  const dateTd = '<td>' + date + '</td>';
  const amountTd = '<td>' + '
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Expense Tracker</title>
</head>

<body>
  <h1>Expense Tracker</h1>
  <h3>Add A New Item:</h3>
  <label>Name: <input text="text" id="name"></label><br>
  <label>Date:<input type="date" id="date"></label><br>
  <label>Amount:<input text="text" id="amount"></label><br>
  <button type="button" id="myButton">Add Expense</button>
  <button type="button" id="clearList">Clear List</button>
  <br>
  <br>
  <br>
  <br>
  <br>
  <table border="1">
    <tr>
      <th>Name</th>
      <th>Date</th>
      <th>Amount</th>
      <th>Remove</th>
    </tr>
    <tbody id="table">

    </tbody>
  </table>


  <script src="script2.js"></script>
</body>

</html>

+ amount + '</td>' + '<td>' + '<button id="removeBtn"type="button" onClick="takeOut(this)">X</button></td>'; const tr = '<tr>' + nameTd + dateTd + amountTd + '</tr>'; document.getElementById('table').insertAdjacentHTML('beforeend', tr); document.getElementById('clearList').onclick = function() { const cl = document.getElementById('table'); while (cl.hasChildNodes()) { cl.removeChild(cl.firstChild); } } document.getElementById('name').value = ''; document.getElementById('amount').value = ''; document.getElementById('date').value = ''; }

尝试删除整个表行HTML JavaScript

绮筵 2025-02-16 03:31:59

您是否将主页道具添加到poffage.json文件中?

have you added the homepage props into the package.json file.?

我应该使用什么而不是本地主机来部署React应用程序?

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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