笑咖

文章 评论 浏览 28

笑咖 2025-02-13 18:36:17

数据

x <- "
2007-01-31 2.72   4.75        2
2007-02-28 2.82   4.75        2
2007-03-31 2.85   4.75        2
2007-04-30 2.74   4.75        3
2007-05-31 2.46   4.75        2
2007-06-30 2.98   4.75        3
2007-07-31 4.19   4.75        3
2007-08-31 4.55   4.75        3
2007-09-30 4.20   4.75        3
2007-10-31 4.36   4.75        3
2007-11-30 5.75   4.76        4
2007-12-31 5.92   4.76        4
2008-01-31 6.95   4.87        4
2008-02-29 7.67   4.87        4
2008-03-31 8.21   4.90        4
2008-04-30 6.86   4.91        1
2008-05-31 6.53   5.07        1
2008-06-30 7.35   5.08        1
2008-07-31 8.00   5.13        4
2008-08-31 8.36   5.19        4
"
df <- read.table(textConnection(x) , header = F)

并使用这两条线

df$V5 <- c(1 ,diff(df$V4))
df[abs(df$V5) > 0 ,][1:4]

#>            V1   V2   V3 V4
#> 1  2007-01-31 2.72 4.75  2
#> 4  2007-04-30 2.74 4.75  3
#> 5  2007-05-31 2.46 4.75  2
#> 6  2007-06-30 2.98 4.75  3
#> 11 2007-11-30 5.75 4.76  4
#> 16 2008-04-30 6.86 4.91  1
#> 19 2008-07-31 8.00 5.13  4

在2022-06-12上由(v2.0.1)

DATA

x <- "
2007-01-31 2.72   4.75        2
2007-02-28 2.82   4.75        2
2007-03-31 2.85   4.75        2
2007-04-30 2.74   4.75        3
2007-05-31 2.46   4.75        2
2007-06-30 2.98   4.75        3
2007-07-31 4.19   4.75        3
2007-08-31 4.55   4.75        3
2007-09-30 4.20   4.75        3
2007-10-31 4.36   4.75        3
2007-11-30 5.75   4.76        4
2007-12-31 5.92   4.76        4
2008-01-31 6.95   4.87        4
2008-02-29 7.67   4.87        4
2008-03-31 8.21   4.90        4
2008-04-30 6.86   4.91        1
2008-05-31 6.53   5.07        1
2008-06-30 7.35   5.08        1
2008-07-31 8.00   5.13        4
2008-08-31 8.36   5.19        4
"
df <- read.table(textConnection(x) , header = F)

and use this two lines

df$V5 <- c(1 ,diff(df$V4))
df[abs(df$V5) > 0 ,][1:4]

#>            V1   V2   V3 V4
#> 1  2007-01-31 2.72 4.75  2
#> 4  2007-04-30 2.74 4.75  3
#> 5  2007-05-31 2.46 4.75  2
#> 6  2007-06-30 2.98 4.75  3
#> 11 2007-11-30 5.75 4.76  4
#> 16 2008-04-30 6.86 4.91  1
#> 19 2008-07-31 8.00 5.13  4

Created on 2022-06-12 by the reprex package (v2.0.1)

在R中,如何根据一列中的重复值保持第一行的第一个出现?

笑咖 2025-02-13 18:31:48

您忘了返回递归电话。
我删除了印刷品,并为您添加了印刷品;您从左到右删除值的方式是错误的,所以我更改了

该代码仍然无法通过所有测试(GET 3373 /3377),因为如果它因大而失败,它不会有效地运行O(n^2)数字由于时间限制

,但是如果您坚持用递归解决这个问题,我认为这是一种方式(或者至少是看起来与您的原始解决方案最相似的方式),

我希望我能帮助我:)随时问我评论中的任何东西

class Solution(object):
    def lastRemaining(self, n: int) -> int:
        run_number=1
        arr=[x for x in range(1,n+1)]
        res=0
        def helper(arr,run_number,res):

            
            if len(arr)==1:
                res=arr[0]
                return res
            elif run_number%2==1:
                arr = erase_from_right(arr)
                run_number+=1
                return helper(arr,run_number,res) #return added here
            else:
                arr = erase_from_left(arr)
                run_number+=1
                return helper(arr,run_number,res) #return added here 

        
        def erase_from_right(arr):
            return [v for i, v in enumerate(arr) if i % 2 == 1]
    
        def erase_from_left(arr):
            new_arr=[]
            while(arr):
                arr.pop()
                if(arr):
                    new_arr.insert(0,arr.pop())                    
            return new_arr
        
        x=helper(arr,run_number,res)
        return x

You forgot to return your recursion calls.
I removed the prints and added them for you also; the way you deleted the values from left to right was wrong, so I changed it

this code still cant pass all of the tests (got 3373 / 3377) since it doesn't run O(n^2) efficiently if it fails for large numbers due to time limits

but if you insist on solving this question with recursion, I think this is the way (or at least the way that looks the most similar to your original solution )

I hope I could help :) feel free to ask me anything in the comments

class Solution(object):
    def lastRemaining(self, n: int) -> int:
        run_number=1
        arr=[x for x in range(1,n+1)]
        res=0
        def helper(arr,run_number,res):

            
            if len(arr)==1:
                res=arr[0]
                return res
            elif run_number%2==1:
                arr = erase_from_right(arr)
                run_number+=1
                return helper(arr,run_number,res) #return added here
            else:
                arr = erase_from_left(arr)
                run_number+=1
                return helper(arr,run_number,res) #return added here 

        
        def erase_from_right(arr):
            return [v for i, v in enumerate(arr) if i % 2 == 1]
    
        def erase_from_left(arr):
            new_arr=[]
            while(arr):
                arr.pop()
                if(arr):
                    new_arr.insert(0,arr.pop())                    
            return new_arr
        
        x=helper(arr,run_number,res)
        return x

Leetcode问题编号390,递归概念

笑咖 2025-02-13 11:02:06

我在 vb.net c#.net 中使用 ntlmauthenticator 创建了一个非常简单的控制台应用程序 &gt; V107。

vb.net:c#.net

Dim clientOptions As New RestClientOptions(BaseUrl) With
        {
            .UseDefaultCredentials = True
        }

        Using client As New RestClient(clientOptions)
            Dim request As New RestRequest(sQ, Method.Post)
            request.AddJsonBody(payload)
            Dim response As RestResponse = Await client.PostAsync(request)

            If response.IsSuccessful Then
                MsgBox(response.Content)
            End If
        End Using

RestClientOptions clientOptions = new RestClientOptions(BaseUrl)
                {
                    UseDefaultCredentials = true
                };

                using (RestClient client = new RestClient(clientOptions))
                {
                    string sQ = "...";
                    RestRequest request = new RestRequest(sQ, Method.Post);
                    request.AddJsonBody("JSON-Body");
                    RestResponse response = await client.PostAsync(request);
                    if (response.IsSuccessful)
                    {
                        Console.WriteLine(response.Content);
                    }
                }

I created a very simple console application in both VB.NET and C#.NET with NtlmAuthenticator and was able to get the code to work with Restsharp > v107.

VB.NET:

Dim clientOptions As New RestClientOptions(BaseUrl) With
        {
            .UseDefaultCredentials = True
        }

        Using client As New RestClient(clientOptions)
            Dim request As New RestRequest(sQ, Method.Post)
            request.AddJsonBody(payload)
            Dim response As RestResponse = Await client.PostAsync(request)

            If response.IsSuccessful Then
                MsgBox(response.Content)
            End If
        End Using

C#.NET

RestClientOptions clientOptions = new RestClientOptions(BaseUrl)
                {
                    UseDefaultCredentials = true
                };

                using (RestClient client = new RestClient(clientOptions))
                {
                    string sQ = "...";
                    RestRequest request = new RestRequest(sQ, Method.Post);
                    request.AddJsonBody("JSON-Body");
                    RestResponse response = await client.PostAsync(request);
                    if (response.IsSuccessful)
                    {
                        Console.WriteLine(response.Content);
                    }
                }

RESTSHARP版本&gt; 107:如何实现ntlmauthenticator?

笑咖 2025-02-12 17:56:56

从头到尾迭代:

for xpos in xpositions[::-1]:
    letters.insert(xpos, c)

Iterate from end to beginning:

for xpos in xpositions[::-1]:
    letters.insert(xpos, c)

在索引列表之前插入元素

笑咖 2025-02-12 07:49:56

您可以在功能中添加paramater以更新这样的精确文本框:

function addText(txt, fieldNumber) {
  var elems = document.getElementsByClassName("inputs");
  if (elems.length <= fieldNumber) return;
  elems[fieldNumber].value = txt;
}

然后称其为“ addtext('text',3)


如果通过“下一个可用”,您的意思是一个没有值的字段,然后编辑您的功能

function addText(txt) {
  var elems = document.getElementsByClassName("inputs");
  console.log("111");
  console.log(elems);
  for (let i = 0; i < elems.length; i++) {
    if (elems[i] && !elems[i].value) {
      elems[i].value = txt;
      break;
    }
  }
}

:演示检查此沙盒:

You can add a paramater to your function to update exact text box like this:

function addText(txt, fieldNumber) {
  var elems = document.getElementsByClassName("inputs");
  if (elems.length <= fieldNumber) return;
  elems[fieldNumber].value = txt;
}

and then call it like "addText('text', 3)"

Check this sandbox
https://codesandbox.io/s/laughing-einstein-byhf0f?file=/src/index.js:299-472

If by "next available", you meant a field which doesn't already have a value then edit your function like this:

function addText(txt) {
  var elems = document.getElementsByClassName("inputs");
  console.log("111");
  console.log(elems);
  for (let i = 0; i < elems.length; i++) {
    if (elems[i] && !elems[i].value) {
      elems[i].value = txt;
      break;
    }
  }
}

For a demo check this sandbox: https://codesandbox.io/s/trusting-browser-lckvy0?file=/index.html

基于按钮单击的下一个空文本输入填充下一个空文本输入

笑咖 2025-02-12 05:33:52

您是否尝试过在本地存储图像,而不是从互联网上采购图像?事实是,如果任何网站都在下降,则不会出现图像。

此外,需要嵌入图像SRC代码。例如:

<img src="https://s1.pngtank.com/thumbnails/63c1c0b584396.png">

Have you tried storing images locally instead of sourcing them from the internet? The thing is if any of the website goes down, the image wont appear.

Furthermore, to embed image src code is required. for example:

<img src="https://s1.pngtank.com/thumbnails/63c1c0b584396.png">

将图像放在美国地图上的R-接收强制故障

笑咖 2025-02-12 02:28:24

您可以尝试将值分为dict,然后将每个字典列转换为单独的列

df = df.applymap(lambda x: dict([x.split('=')]))
out = pd.concat([df[col].apply(pd.Series) for col in df.columns], axis=1)
print(out)

   id formatted_value weighted_value   person_name
0  10       U$ 20.000       U$ 20000  Natys Person
1  11       U$ 10.000       U$ 10000    Mike Tyson

You can try split the value into dict and convert each dictionary column to separate column

df = df.applymap(lambda x: dict([x.split('=')]))
out = pd.concat([df[col].apply(pd.Series) for col in df.columns], axis=1)
print(out)

   id formatted_value weighted_value   person_name
0  10       U$ 20.000       U$ 20000  Natys Person
1  11       U$ 10.000       U$ 10000    Mike Tyson

根据dataFrame行中的字符串重命名列

笑咖 2025-02-11 20:31:15

.foreach()将不等待异步函数。相反,将。 -MAP与Promise.last的组合使用。

等待Promise.all(MessageArray.map(async(message)=&gt; {...})); >

.forEach() will not wait for async functions. Instead, use a combination of .map with Promise.all.

await Promise.all(messageArray.map(async (message) => {...}));

执行最后一行后,foreach循环完成

笑咖 2025-02-11 19:31:25

关于MCC,您需要了解一些知识。当您运行上载命令一个没有元数据的NFT将被铸造到您作为权威提供的钱包中( -K 参数),此空的NFT是默认的集合NFT,将充当您收藏中所有未打印的NFT的肖像。您看到集合nft 的原因是因为NFT没有元数据。另外,除非您使用 set_collection 给定为 -m 参数,否则所有未明确的NFT都附加到本集合中您的candymachine有0个铸造物品。

为了解决集合NFT,您只需要在铸造的默认集合NFT中添加元数据即可。如果您在mainnet-beta上,我建议您使用此网站,您也可以使用 metaboss (UT您必须将UR元数据上传到之前的存储空间)。

您可以看到使用显示命令将输出有关集合NFT的以下信息(以及有关CM的更多信息): Collection Mint:gfe ... 6Q9 ,该 Collection> Collection Mint 如果其元数据为空,则是ur cm的NFT,您只需要更新它,因此每个铸造的NFT都会将其附加到非空的NFT作为集合中。

There is something you need to know regarding MCC. When you run upload command a NFT without metadata will be minted to the wallet that you provide as authority (-k parameter), this empty NFT is the default collection NFT and will act as portrait of all the unminted NFTs inside ur collection. The reason that you see Collection NFT as portrait is because that NFT has no metadata. Also all unminted NFTs are attached to this collection unless you use set_collection given as -m parameter a new collection id (another created collection NFT), but this can only be done if your CandyMachine has 0 minted items.

In order to solve the Collection NFT you just have to add metadata to the minted default collection NFT. If you are on mainnet-beta I recommend you to use this website, you can also use metaboss (ut you will have to upload ur metadata to an storage before).

You can see what is the collection NFT that is attached to ur CandyMachine using the show command that will output the following info about the collection NFT (and more info about the CM): Collection mint: Gfe...6q9, that Collection mint is the NFT that is attached to ur CM as collection if its metadata is empty you just have to update it so every minted NFT will be attached to a non-empty NFT as collection.

在铸造之前,如何更改Solana系列的名称?

笑咖 2025-02-11 12:25:31

要取消组,您可以 在分组的数组元素上,带有嵌套 map() map()的分组对象。

const mockData = { 'test-1': [{ message: 'test#1.1' }, { message: 'test#1.2' }], 'test-2': [{ message: 'test#2.1' }, { message: 'test#2.2' }] };

const result = Object.entries(mockData).flatMap(([id, vs]) => vs.map(v => ({ id, ...v })));

console.log(result);

或使用 for。 .. 如果您想循环

const mockData = { 'test-1': [{ message: 'test#1.1' }, { message: 'test#1.2' }], 'test-2': [{ message: 'test#2.1' }, { message: 'test#2.2' }] };

const result = [];
for (const [id, messages] of Object.entries(mockData)) {
  for (const message of messages) {
    result.push({ id, ...message });
  }
}

console.log(result);

To ungroup you can flatMap the Object.entries of the grouped object with a nested map() call over the grouped array elements.

const mockData = { 'test-1': [{ message: 'test#1.1' }, { message: 'test#1.2' }], 'test-2': [{ message: 'test#2.1' }, { message: 'test#2.2' }] };

const result = Object.entries(mockData).flatMap(([id, vs]) => vs.map(v => ({ id, ...v })));

console.log(result);

Or using a for...of loop if you'd rather

const mockData = { 'test-1': [{ message: 'test#1.1' }, { message: 'test#1.2' }], 'test-2': [{ message: 'test#2.1' }, { message: 'test#2.2' }] };

const result = [];
for (const [id, messages] of Object.entries(mockData)) {
  for (const message of messages) {
    result.push({ id, ...message });
  }
}

console.log(result);

带有数组数组的打字稿对象

笑咖 2025-02-11 09:47:41

最快的是:

while read -r ITEM; do
    OPERATION
done < <(COMMAND)

或一行:

while read -r ITEM; do OPERATION; done < <(COMMAND)

The fastest was:

while read -r ITEM; do
    OPERATION
done < <(COMMAND)

Or in one line:

while read -r ITEM; do OPERATION; done < <(COMMAND)

循环结束后循环时如何将输入输入到bash中并保留变量

笑咖 2025-02-10 20:53:40

只需在附加命令之前将所有列转换为字符串:

if file.suffix.lower() == '.xlsx':
     frame = pd.read_excel(file, header=0, engine='openpyxl')
     frame =frame.astype(str)
(...)
     all_df_list.append(frame)


elif file.suffix.lower() == '.csv':
     frameCSV = pd.read_csv(file, encoding="utf-8")
     frameCSV =frameCSV.astype(str)
(..)
     all_df_list.append(frameCSV )

xls=pd.concat(all_df_list)
xls.to_sql(table, con=engine, if_exists='append', index=False, chunksize=10000)

Just convert all columns to strings before append command :

if file.suffix.lower() == '.xlsx':
     frame = pd.read_excel(file, header=0, engine='openpyxl')
     frame =frame.astype(str)
(...)
     all_df_list.append(frame)


elif file.suffix.lower() == '.csv':
     frameCSV = pd.read_csv(file, encoding="utf-8")
     frameCSV =frameCSV.astype(str)
(..)
     all_df_list.append(frameCSV )

xls=pd.concat(all_df_list)
xls.to_sql(table, con=engine, if_exists='append', index=False, chunksize=10000)

Python错误:每个表中的列名必须是唯一的。如何解决?

笑咖 2025-02-10 16:01:47

正如特拉维斯(Travis)和其他人所提到的那样,其他事情也可能导致额外的输出,而设定的nocount不会阻止。

我在过程开始时已经设置了Nocount,但在结果集中收到了警告消息。

我在脚本开始时设置了ANSI警告,以删除错误消息。

SET ANSI_WARNINGS OFF

希望这对某人有帮助。

As Travis and others have mentioned, other things can also cause extra output that SET NOCOUNT ON will not prevent.

I had SET NOCOUNT ON at the start of my procedure but was receiving warning messages in my results set.

I set ansi warnings off at the beginning of my script in order to remove the error messages.

SET ANSI_WARNINGS OFF

Hopefully this helps someone.

MSSQL2008 -PYODBC-先前的SQL不是查询

笑咖 2025-02-10 10:15:29

我建议选择一个select-case(C#中的开关案例),而不是if-else,作为模式匹配的形式。请参阅:选择案例语句

I would suggest a Select-Case (switch-case in C#) instead of If-Else, as a form of pattern matching. See: Select Case statement

想在VBA中进行多个if语句

笑咖 2025-02-10 09:48:42

尝试将此选项传递给usefetch: initialcache:false 请参见更多

Try passing this option to useFetch: initialCache: false. See more

nuxt3 usefetch仅偶尔检索数据

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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