太阳哥哥

文章 评论 浏览 28

太阳哥哥 2025-02-21 02:06:00

从本质上讲,您具有以下结构:

<form method="post" action="ServletPacientes">
    <a href="ServletPacientes?Param=editar&dni=<%=a.getDni()%>">
        <input type="submit" value="Editar">
    </a>
</form>

这意味着,当您单击此“ editar”按钮时,将作为邮政请求进行表单提交。该请求应该在servlet侧的 dopost 方法处理,并且URL为/servletpacientes 。这就是为什么您导航到/servletpacientes 。包装&lt; a&gt; 元素中的链接将无效。

如果您期望导航到 servletpacientes之类的东西?param = editar&amp; dni = 20216447 ,您必须使嵌套 input> input> input element a普通按钮,而不是提交&lt; input type =“ button” value =“ editar”&gt;

You essentially have the following structure:

<form method="post" action="ServletPacientes">
    <a href="ServletPacientes?Param=editar&dni=<%=a.getDni()%>">
        <input type="submit" value="Editar">
    </a>
</form>

This means that when you click on this "Editar" button, a form submission will happen as a POST request. This request is supposed to be processed by a doPost method on the servlet side, and the URL would be /ServletPacientes. This is why you navigate to /ServletPacientes. The link in the wrapping <a> element will have no effect.

If you expect to navigate to something like ServletPacientes?Param=editar&dni=20216447, you'll have to make the nested input element a regular button, not a submit: <input type="button" value="Editar">.

为什么我的表格不会将我重定向到即时通行的路线?

太阳哥哥 2025-02-20 23:46:00

这是一个存储的POC,它将根据输入字符串和指定的定界符产生一个动态列的表结果。

如果您正在寻找一种基于值生成动态列名称的方法,我建议您在此处访问Felipe Hoffa的博客条目:
https://medium.com/medium.com/snowflake/snowflake/dynemic-pivots-pivots-pivots-pivots-pivots-po- snowflake-c76393987c in-sql-with-with-snowflake

create or replace procedure pivot_dyn_results(input string, delimiter string) 
returns table ()
language SQL 
AS
declare

max_count integer default 0;
lcount integer default 0;
rs resultset;
stmt1 string;
stmt2 string;

begin

-- Get number of delimiter separated values (assumes no leading or trailing delimiter)
select regexp_count(:input, '\\'||:delimiter, 1) into :max_count from dual;

-- Generate the initial row-based result set of parsed values
stmt1 := 'SELECT * from lateral split_to_table(?,?)';

-- Build dynamic query to produce the pivoted column based results
stmt2 := 'select * from (select * from table(result_scan(last_query_id(-1)))) pivot(max(value) for index in (';

-- initialize look counter for resulting columns
lcount := 1;
stmt2 := stmt2 || '\'' || lcount || '\'';

-- append pivot statement for each column to be represented
FOR l in 1 to max_count do
lcount := lcount + 1;
stmt2 := stmt2 || ',\'' || lcount || '\'';
END FOR;

-- close out the pivot statement
stmt2 := stmt2 || '))';

-- execute the 
EXECUTE IMMEDIATE :stmt1 using (input, delimiter);
rs := (EXECUTE IMMEDIATE :stmt2);

return table(rs);
end;

调用:
调用pivot_dyn_results([string],[DeLimiter]);

call pivot_dyn_results('Sales External?HR?Billing?Purchase Department','?');

结果:

“

Here's a stored proc that will produce a table result with a dynamic set of columns based on the input string and specified delimiter.

If you are looking for a way to generate dynamic column names based on values, I recommend visiting Felipe Hoffa's blog entry here:
https://medium.com/snowflake/dynamic-pivots-in-sql-with-snowflake-c763933987c

create or replace procedure pivot_dyn_results(input string, delimiter string) 
returns table ()
language SQL 
AS
declare

max_count integer default 0;
lcount integer default 0;
rs resultset;
stmt1 string;
stmt2 string;

begin

-- Get number of delimiter separated values (assumes no leading or trailing delimiter)
select regexp_count(:input, '\\'||:delimiter, 1) into :max_count from dual;

-- Generate the initial row-based result set of parsed values
stmt1 := 'SELECT * from lateral split_to_table(?,?)';

-- Build dynamic query to produce the pivoted column based results
stmt2 := 'select * from (select * from table(result_scan(last_query_id(-1)))) pivot(max(value) for index in (';

-- initialize look counter for resulting columns
lcount := 1;
stmt2 := stmt2 || '\'' || lcount || '\'';

-- append pivot statement for each column to be represented
FOR l in 1 to max_count do
lcount := lcount + 1;
stmt2 := stmt2 || ',\'' || lcount || '\'';
END FOR;

-- close out the pivot statement
stmt2 := stmt2 || '))';

-- execute the 
EXECUTE IMMEDIATE :stmt1 using (input, delimiter);
rs := (EXECUTE IMMEDIATE :stmt2);

return table(rs);
end;

Invocation:
call pivot_dyn_results([string],[delimiter]);

call pivot_dyn_results('Sales External?HR?Billing?Purchase Department','?');

Results:

SEQ   '1'               '2'  '3' '4'
1    Sales External HR  Billing Purchase Department

在分离器之间提取单词

太阳哥哥 2025-02-20 19:53:31

JavaScript本身本身就是实现的,因此语言本身有意不存在诸如内存地址之类的概念。在语言之外,您可以使用浏览器的调试工具来获取内存快照,并且可能包含信息。但是请注意,没有真正的保证对象会保留其地址。

JavaScript itself is meant to be implementation-agnostic, so concepts like memory addresses are intentionally absent from the language itself. Outside of the language, you can use the browser's debugging tools to take a memory snapshot, and that might contain the information. Note, however, that there is no real guarantee that an object will retain its address.

有什么方法可以获取JavaScript变量内存地址?

太阳哥哥 2025-02-20 12:23:33

但是,下面不是答案,而是另一个解决方案。

function findLongestWordLength(str) {
 
 const splitted = str.split(' ');
 let wordLength =0;
 splitted.forEach((word) =>{
     const wordSplitted = word.split('');
     if(wordSplitted.length > wordLength){
      wordLength = wordSplitted.length;
     }
 });

  return wordLength;

}

console.log(findLongestWordLength("Thep quick brown fox jumped over the lazy dog"));

Though, below is not the answer, but is another solution.

function findLongestWordLength(str) {
 
 const splitted = str.split(' ');
 let wordLength =0;
 splitted.forEach((word) =>{
     const wordSplitted = word.split('');
     if(wordSplitted.length > wordLength){
      wordLength = wordSplitted.length;
     }
 });

  return wordLength;

}

console.log(findLongestWordLength("Thep quick brown fox jumped over the lazy dog"));

freecodecamp“找到最长的单词”

太阳哥哥 2025-02-20 05:46:36

您需要查找的索引[3,3,3] 为此,您可以使用 all(axis = -1),然后替换为 [0,0, 0]

row, col = np.where((c==3).all(-1))
c[row, col] = [0,0,0]
print(c)

输出:

[[[0 0 0]
  [2 2 2]
  [0 0 0]
  [4 4 4]]

 [[1 1 1]
  [2 2 2]
  [7 3 3]
  [4 4 4]]

 [[1 1 1]
  [0 0 0]
  [0 0 0]
  [4 4 4]]

 [[1 1 1]
  [2 2 2]
  [3 8 3]
  [0 0 0]]

 [[0 0 0]
  [2 2 2]
  [0 0 0]
  [4 4 4]]]

You need find index of [3,3,3] for this you can use all(axis=-1), then replace with [0,0,0]:

row, col = np.where((c==3).all(-1))
c[row, col] = [0,0,0]
print(c)

Output:

[[[0 0 0]
  [2 2 2]
  [0 0 0]
  [4 4 4]]

 [[1 1 1]
  [2 2 2]
  [7 3 3]
  [4 4 4]]

 [[1 1 1]
  [0 0 0]
  [0 0 0]
  [4 4 4]]

 [[1 1 1]
  [2 2 2]
  [3 8 3]
  [0 0 0]]

 [[0 0 0]
  [2 2 2]
  [0 0 0]
  [4 4 4]]]

如何替换“数组元素” numpy.ndarray关于条件而不使用显式循环?

太阳哥哥 2025-02-20 00:14:24

[slug] 用于具有嵌套路由。但是正确的是 [... slug] .js info

示例:myurl.com/article/ [id]/[otherid]

在上面的示例中,我们可以看到[id]中可以是嵌套的孩子。您可以根据需要命名此参数。

如果您想将结构作为 myurl.com/article/55 ,则需要以下结构:

pages 文件夹中:

  1. 您创建一个文件夹文章 pages/article
  2. 您创建2个文件:index.js(or .tsx)和 [id] .js (您可以将其命名为[slug ] .js或[Specialid] .js-无论是什么名称
  3. ,您都会获得具有参数名称的信息

import { useRouter } from 'next/router'

const Post = () => {
  const router = useRouter()
  //same name as name of your file, can be [slug].js; [specialId].js - any name you want
  const { pid } = router.query
  //result will be '55' (string)
  return <p>Post: {pid}</p>
}

export default Post

[slug] is used to have nested routes. But correct is [...slug].js (info)

Example: myurl.com/article/[id]/[otherid]

In the example above we can see that in [id] can be nested children. You can name this param as you want.

If you want to have your structure as myurl.com/article/55, you need to have structure as follow:

In your pages folder:

  1. You create a folder article (pages/article)
  2. You create 2 files: index.js (or .tsx) and [id].js (you can name as [slug].js or [specialId].js - no matter the name
  3. After, you are getting info with param name created.

Here is example of the code (URL: myurl.com/article/55; file: pages/article/[pid].js)

import { useRouter } from 'next/router'

const Post = () => {
  const router = useRouter()
  //same name as name of your file, can be [slug].js; [specialId].js - any name you want
  const { pid } = router.query
  //result will be '55' (string)
  return <p>Post: {pid}</p>
}

export default Post

如何在NextJ中使用slug URL

太阳哥哥 2025-02-19 20:46:03

还要考虑以下方法

select name_one as player, 
  array_agg(struct(name_two as most_from, points as most_points) order by points desc limit 1)[offset(0)].*,
  array_agg(struct(name_two as least_from, points as least_points) order by points limit 1)[offset(0)].* 
from (
  select name_one, name_two, sum(points_name_one) points
  from your_table group by 1,2 
  union all
  select name_two, name_one, sum(points_name_two) 
  from your_table group by 1,2
)
group by player  

,如果将方法应用于您的问题中的样本数据-USTUPS

”在此处输入图像说明”

Consider also below approach

select name_one as player, 
  array_agg(struct(name_two as most_from, points as most_points) order by points desc limit 1)[offset(0)].*,
  array_agg(struct(name_two as least_from, points as least_points) order by points limit 1)[offset(0)].* 
from (
  select name_one, name_two, sum(points_name_one) points
  from your_table group by 1,2 
  union all
  select name_two, name_one, sum(points_name_two) 
  from your_table group by 1,2
)
group by player  

if applied to sample data in your question - output is

enter image description here

countif bigquery

太阳哥哥 2025-02-19 02:11:04

解决此问题的最佳方法是在 > - 怀疑您的TLP损坏。

支持将能够对您进行整理(假设您尚未分类)

请参阅属性的配置文件!

The best way of resolving this would be to contact LDRA Support at [email protected] - the suspicion is that you have a corrupted TLP.

Support will be able to sort you out (assuming you are not already sorted)

See profile for affiliation!

$(ProjectConfiguration)在LDRA TBRUN TCF文件中设置在哪里?

太阳哥哥 2025-02-18 18:18:15

相关非静态数据成员初始化:

在科纳(Kona)提出的有关标识符范围的问题:

在KONA在Kona举行的核心工作组的讨论中,就初始化器中的标识符范围提出了一个问题。我们是否要允许班级范围具有前向查找的可能性?还是我们要要求在解析时定义良好的初始化器?

所需的内容:

类scope查找的动机是,我们希望能够将任何内容放入非静态数据成员的初始化器中,而我们可以将其放入mem-Inialializer中,而无需显着更改语义(Modulo Direct Direct Initialization Vs.复制初始化):

int x();

struct S {
    int i;
    S() : i(x()) {} // currently well-formed, uses S::x()
    // ...
    static int x();
};

struct T {
    int i = x(); // should use T::x(), ::x() would be a surprise
    // ...
    static int x();
};

问题1:

不幸的是,这使得在解析声明时形成了“(表达列表)”的初始化形式:

   struct S {
        int i(x); // data member with initializer
        // ...
        static int x;
    };

    struct T {
        int i(x); // member function declaration
        // ...
        typedef int x;
    };

一种可能的解决方案是依靠现有规则,即如果声明可以是对象或函数,则是一个函数:

 struct S {
        int i(j); // ill-formed...parsed as a member function,
                  // type j looked up but not found
        // ...
        static int j;
    };

类似的解决方案将是应用另一个仅在模板中使用的现有规则,即如果t可以是一种类型或其他类型,那么它是其他的。如果我们真的是指类型:

,我们可以使用“键入”

struct S {
        int i(x); // unabmiguously a data member
        int j(typename y); // unabmiguously a member function
    };

这两种解决方案都引入了许多用户可能会误解的微妙之处(正如Comp.lang.lang.c ++上的许多问题所证明的那样,关于“ Int I()”;在块范围内没有声明默认初始化的int)。

本文提出的解决方案是仅允许“ = initializer-clause”和“ {initializer-list}”表单。例如,在大多数情况下解决了歧义问题,例如:

HashingFunction hash_algorithm{"MD5"};

在这里,我们无法使用= form,因为HasningFunction的构造函数是明确的。
在特别棘手的情况下,可能必须两次提及一种类型。考虑:

   vector<int> x = 3; // error:  the constructor taking an int is explicit
   vector<int> x(3);  // three elements default-initialized
   vector<int> x{3};  // one element with the value 3

在这种情况下,我们必须使用适当的符号在两个替代方案之间进行选择:

vector<int> x = vector<int>(3); // rather than vector<int> x(3);
vector<int> x{3}; // one element with the value 3

问题2:

另一个问题是,因为我们建议对静态数据成员的初始化规则没有更改,因此添加静态关键字可能会使形成良好的初始化器不正确:

   struct S {
               const int i = f(); // well-formed with forward lookup
        static const int j = f(); // always ill-formed for statics
        // ...
        constexpr static int f() { return 0; }
    };

问题3:

第三个问题是,类Scope查找可能会将编译时错误转换为运行时错误:

struct S {
    int i = j; // ill-formed without forward lookup, undefined behavior with
    int j = 3;
};

(除非由编译器捕获,否

提案:

CWG在科纳(Kona)进行了6比3的稻草民意调查,以支持课堂镜头。这就是本文提出的,非静态数据成员的初始化器仅限于“ = initializer-care”和“ {initializer-list}”表单。

我们相信:

问题1:这个问题不会发生,因为我们不建议()符号。 = and {}初始化符号不会遭受此问题的困扰。

问题2:添加静态关键字有很多差异,这是其中最少的。

问题3:这不是一个新问题,而是与构造函数初始化器已经存在的命中序列问题。

The rationale behind this choice is explicitly mentioned in the related proposal for non static data member initializers :

An issue raised in Kona regarding scope of identifiers:

During discussion in the Core Working Group at the September ’07 meeting in Kona, a question arose about the scope of identifiers in the initializer. Do we want to allow class scope with the possibility of forward lookup; or do we want to require that the initializers be well-defined at the point that they’re parsed?

What’s desired:

The motivation for class-scope lookup is that we’d like to be able to put anything in a non-static data member’s initializer that we could put in a mem-initializer without significantly changing the semantics (modulo direct initialization vs. copy initialization):

int x();

struct S {
    int i;
    S() : i(x()) {} // currently well-formed, uses S::x()
    // ...
    static int x();
};

struct T {
    int i = x(); // should use T::x(), ::x() would be a surprise
    // ...
    static int x();
};

Problem 1:

Unfortunately, this makes initializers of the “( expression-list )” form ambiguous at the time that the declaration is being parsed:

   struct S {
        int i(x); // data member with initializer
        // ...
        static int x;
    };

    struct T {
        int i(x); // member function declaration
        // ...
        typedef int x;
    };

One possible solution is to rely on the existing rule that, if a declaration could be an object or a function, then it’s a function:

 struct S {
        int i(j); // ill-formed...parsed as a member function,
                  // type j looked up but not found
        // ...
        static int j;
    };

A similar solution would be to apply another existing rule, currently used only in templates, that if T could be a type or something else, then it’s something else; and we can use “typename” if we really mean a type:

struct S {
        int i(x); // unabmiguously a data member
        int j(typename y); // unabmiguously a member function
    };

Both of those solutions introduce subtleties that are likely to be misunderstood by many users (as evidenced by the many questions on comp.lang.c++ about why “int i();” at block scope doesn’t declare a default-initialized int).

The solution proposed in this paper is to allow only initializers of the “= initializer-clause” and “{ initializer-list }” forms. That solves the ambiguity problem in most cases, for example:

HashingFunction hash_algorithm{"MD5"};

Here, we could not use the = form because HasningFunction’s constructor is explicit.
In especially tricky cases, a type might have to be mentioned twice. Consider:

   vector<int> x = 3; // error:  the constructor taking an int is explicit
   vector<int> x(3);  // three elements default-initialized
   vector<int> x{3};  // one element with the value 3

In that case, we have to chose between the two alternatives by using the appropriate notation:

vector<int> x = vector<int>(3); // rather than vector<int> x(3);
vector<int> x{3}; // one element with the value 3

Problem 2:

Another issue is that, because we propose no change to the rules for initializing static data members, adding the static keyword could make a well-formed initializer ill-formed:

   struct S {
               const int i = f(); // well-formed with forward lookup
        static const int j = f(); // always ill-formed for statics
        // ...
        constexpr static int f() { return 0; }
    };

Problem 3:

A third issue is that class-scope lookup could turn a compile-time error into a run-time error:

struct S {
    int i = j; // ill-formed without forward lookup, undefined behavior with
    int j = 3;
};

(Unless caught by the compiler, i might be intialized with the undefined value of j.)

The proposal:

CWG had a 6-to-3 straw poll in Kona in favor of class-scope lookup; and that is what this paper proposes, with initializers for non-static data members limited to the “= initializer-clause” and “{ initializer-list }” forms.

We believe:

Problem 1: This problem does not occur as we don’t propose the () notation. The = and {} initializer notations do not suffer from this problem.

Problem 2: adding the static keyword makes a number of differences, this being the least of them.

Problem 3: this is not a new problem, but is the same order-of-initialization problem that already exists with constructor initializers.

为什么可以使用括号的成员初始化器?

太阳哥哥 2025-02-18 17:57:17

spath 是正确的命令,但它仅适用于有效的JSON字符串。 jsonlint.com认为给定的字符串无效。

这是一个使用 rex 提取版本ID的解决方法。

index="$index" "$filterString"
| rex field=context "version=\\\"(?<versionId>[^\\\"]+)"
| stats count by versionId

spath is the right command, but it only works with valid JSON strings. The given string is considered invalid by jsonlint.com.

Here is a workaround that uses rex to extract the version ID.

index="$index" "$filterString"
| rex field=context "version=\\\"(?<versionId>[^\\\"]+)"
| stats count by versionId

使用spath从splunk中的json日志中读取字段

太阳哥哥 2025-02-18 09:45:02

您可以使用 fieldViewBuilder 为此。
这样的事情:

  @override
  Widget build(BuildContext context) {
    return Autocomplete<String>(
      optionsBuilder: (TextEditingValue textEditingValue) {
        if (textEditingValue.text == '') {
          return const Iterable<String>.empty();
        }
        return _kOptions.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      fieldViewBuilder: (BuildContext context, 
                         TextEditingController textEditingController,
                         FocusNode focusNode,
                         VoidCallback onFieldSubmitted) {
          return TextFormField(
            controller: textEditingController,
            focusNode: focusNode,
            onFieldSubmitted: (str) => onFieldSubmitted(),
            decoration: const InputDecoration(
              border: UnderlineInputBorder(),
              contentPadding: EdgeInsets.only(left: 12.0),
            )
          );
      },
      onSelected: (String selection) {
        debugPrint('You just selected $selection');
      },
    );
  }

You can use fieldViewBuilder for that.
Something like this:

  @override
  Widget build(BuildContext context) {
    return Autocomplete<String>(
      optionsBuilder: (TextEditingValue textEditingValue) {
        if (textEditingValue.text == '') {
          return const Iterable<String>.empty();
        }
        return _kOptions.where((String option) {
          return option.contains(textEditingValue.text.toLowerCase());
        });
      },
      fieldViewBuilder: (BuildContext context, 
                         TextEditingController textEditingController,
                         FocusNode focusNode,
                         VoidCallback onFieldSubmitted) {
          return TextFormField(
            controller: textEditingController,
            focusNode: focusNode,
            onFieldSubmitted: (str) => onFieldSubmitted(),
            decoration: const InputDecoration(
              border: UnderlineInputBorder(),
              contentPadding: EdgeInsets.only(left: 12.0),
            )
          );
      },
      onSelected: (String selection) {
        debugPrint('You just selected $selection');
      },
    );
  }

自动完整文本字段中的填充

太阳哥哥 2025-02-18 05:25:21

尝试以下操作:


import numpy as np


df['opens'] = (
    df['opens']
    .str.strip('[')
    .str.strip(']')
    .str.strip(' ')
    .str.replace(', ', ',')
    .str.split(',')
    .apply(np.array, dtype=float)
)

您要遇到的错误( valueError:无法将字符串转换为float:'[[63.240001 )是由于列中的值 opens opens 被读为字符串,而不是值列表。

例如,打开的第一个值是:

"[63.2400016784668, 62.20000076293945, 61.91999816894531, 61.40000152587891, 60.65999984741211, 60.04000091552734, 61.27999877929688, 60.0, 59.11999893188477, 57.88000106811523, 57.7599983215332, 59.04000091552734, 58.18000030517578, 55.29999923706055, 54.13999938964844, 54.52000045776367, 54.13999938964844, 56.72000122070312, 57.0, 58.29999923706055, 58.34000015258789, 58.04000091552734, 58.5, 58.45999908447266, 58.34000015258789, 56.09999847412109, 56.72000122070312, 58.5, 59.13999938964844, 58.41999816894531, 58.65999984741211, 57.90000152587891, 56.43999862670898, 55.7599983215332, 56.27999877929688, 55.22000122070312, 56.5, 56.58000183105469, 56.72000122070312, 56.38000106811523, 55.72000122070312, 55.88000106811523, 56.7400016784668, 58.06000137329102, 58.79999923706055, 59.40000152587891, 59.56000137329102, 58.18000030517578, 58.11999893188477, 57.72000122070312, 57.79999923706055, 56.88000106811523, 57.31999969482422, 56.11999893188477, 56.59999847412109, 56.38000106811523, 57.15999984741211, 56.08000183105469, 56.93999862670898, 57.86000061035156, 57.88000106811523, 58.54000091552734, 58.70000076293945, 57.81999969482422, 58.68000030517578, 58.58000183105469]"

而不是类似的内容:

['63.2400016784668',
 '62.20000076293945',
 '61.91999816894531',
 '61.40000152587891',
 '60.65999984741211',
 '60.04000091552734',
 '61.27999877929688',
 '60.0',
 '59.11999893188477',
 '57.88000106811523',
 '57.7599983215332',
 '59.04000091552734',
 '58.18000030517578',
 '55.29999923706055',
 '54.13999938964844',
 '54.52000045776367',
 '54.13999938964844',
 '56.72000122070312',
 '57.0',
 '58.29999923706055',
 '58.34000015258789',
 '58.04000091552734',
 '58.5',
 '58.45999908447266',
 '58.34000015258789',
 '56.09999847412109',
 '56.72000122070312',
 '58.5',
 '59.13999938964844',
 '58.41999816894531',
 '58.65999984741211',
 '57.90000152587891',
 '56.43999862670898',
 '55.7599983215332',
 '56.27999877929688',
 '55.22000122070312',
 '56.5',
 '56.58000183105469',
 '56.72000122070312',
 '56.38000106811523',
 '55.72000122070312',
 '55.88000106811523',
 '56.7400016784668',
 '58.06000137329102',
 '58.79999923706055',
 '59.40000152587891',
 '59.56000137329102',
 '58.18000030517578',
 '58.11999893188477',
 '57.72000122070312',
 '57.79999923706055',
 '56.88000106811523',
 '57.31999969482422',
 '56.11999893188477',
 '56.59999847412109',
 '56.38000106811523',
 '57.15999984741211',
 '56.08000183105469',
 '56.93999862670898',
 '57.86000061035156',
 '57.88000106811523',
 '58.54000091552734',
 '58.70000076293945',
 '57.81999969482422',
 '58.68000030517578',
 '58.58000183105469']

Try this:


import numpy as np


df['opens'] = (
    df['opens']
    .str.strip('[')
    .str.strip(']')
    .str.strip(' ')
    .str.replace(', ', ',')
    .str.split(',')
    .apply(np.array, dtype=float)
)

The error you're getting (ValueError: could not convert string to float: '[[63.240001) is due to the fact that the values from the column opens are being read as strings, instead of lists of values.

For example, the first value of opens being read is:

"[63.2400016784668, 62.20000076293945, 61.91999816894531, 61.40000152587891, 60.65999984741211, 60.04000091552734, 61.27999877929688, 60.0, 59.11999893188477, 57.88000106811523, 57.7599983215332, 59.04000091552734, 58.18000030517578, 55.29999923706055, 54.13999938964844, 54.52000045776367, 54.13999938964844, 56.72000122070312, 57.0, 58.29999923706055, 58.34000015258789, 58.04000091552734, 58.5, 58.45999908447266, 58.34000015258789, 56.09999847412109, 56.72000122070312, 58.5, 59.13999938964844, 58.41999816894531, 58.65999984741211, 57.90000152587891, 56.43999862670898, 55.7599983215332, 56.27999877929688, 55.22000122070312, 56.5, 56.58000183105469, 56.72000122070312, 56.38000106811523, 55.72000122070312, 55.88000106811523, 56.7400016784668, 58.06000137329102, 58.79999923706055, 59.40000152587891, 59.56000137329102, 58.18000030517578, 58.11999893188477, 57.72000122070312, 57.79999923706055, 56.88000106811523, 57.31999969482422, 56.11999893188477, 56.59999847412109, 56.38000106811523, 57.15999984741211, 56.08000183105469, 56.93999862670898, 57.86000061035156, 57.88000106811523, 58.54000091552734, 58.70000076293945, 57.81999969482422, 58.68000030517578, 58.58000183105469]"

instead of something like:

['63.2400016784668',
 '62.20000076293945',
 '61.91999816894531',
 '61.40000152587891',
 '60.65999984741211',
 '60.04000091552734',
 '61.27999877929688',
 '60.0',
 '59.11999893188477',
 '57.88000106811523',
 '57.7599983215332',
 '59.04000091552734',
 '58.18000030517578',
 '55.29999923706055',
 '54.13999938964844',
 '54.52000045776367',
 '54.13999938964844',
 '56.72000122070312',
 '57.0',
 '58.29999923706055',
 '58.34000015258789',
 '58.04000091552734',
 '58.5',
 '58.45999908447266',
 '58.34000015258789',
 '56.09999847412109',
 '56.72000122070312',
 '58.5',
 '59.13999938964844',
 '58.41999816894531',
 '58.65999984741211',
 '57.90000152587891',
 '56.43999862670898',
 '55.7599983215332',
 '56.27999877929688',
 '55.22000122070312',
 '56.5',
 '56.58000183105469',
 '56.72000122070312',
 '56.38000106811523',
 '55.72000122070312',
 '55.88000106811523',
 '56.7400016784668',
 '58.06000137329102',
 '58.79999923706055',
 '59.40000152587891',
 '59.56000137329102',
 '58.18000030517578',
 '58.11999893188477',
 '57.72000122070312',
 '57.79999923706055',
 '56.88000106811523',
 '57.31999969482422',
 '56.11999893188477',
 '56.59999847412109',
 '56.38000106811523',
 '57.15999984741211',
 '56.08000183105469',
 '56.93999862670898',
 '57.86000061035156',
 '57.88000106811523',
 '58.54000091552734',
 '58.70000076293945',
 '57.81999969482422',
 '58.68000030517578',
 '58.58000183105469']

为什么可以将数据框列转换为float

太阳哥哥 2025-02-17 22:50:37

如果您知道您将始终在前面有 d。

        private static KeyValuePair<string, string> Helper(KeyValuePair<string, string> x)
        {
            // starting index of 2, to skip "d.", and length of the key minus "d." and ".f"
            var substring = x.Key.Substring(2, x.Key.Length - 4);
            return new KeyValuePair<string, string>(substring, x.Value);
        }

另外,如果您实际上将在前面和后面具有更多字符(而不是 d。 .f ),则可以计算第一个的索引。 和最后一个,然后从中创建一个子字符串:

        private static KeyValuePair<string, string> Helper(KeyValuePair<string, string> x)
        {
            // d.b.f
            var startIndex = x.Key.IndexOf('.') + 1; // 2
            var endIndex = x.Key.LastIndexOf('.'); // 3
            var length = endIndex - startIndex; // 1
            var substring = x.Key.Substring(startIndex, length); // b
            return new KeyValuePair<string, string>(substring, x.Value);
        }

If you know that you will always have d. in front, and .f on the end, you could simply do a substring of your key.

        private static KeyValuePair<string, string> Helper(KeyValuePair<string, string> x)
        {
            // starting index of 2, to skip "d.", and length of the key minus "d." and ".f"
            var substring = x.Key.Substring(2, x.Key.Length - 4);
            return new KeyValuePair<string, string>(substring, x.Value);
        }

Alternatively, if you will actually have more characters in front and behind (instead of just d. and .f), you could calculate the index of the first . and last . and then create a substring from that:

        private static KeyValuePair<string, string> Helper(KeyValuePair<string, string> x)
        {
            // d.b.f
            var startIndex = x.Key.IndexOf('.') + 1; // 2
            var endIndex = x.Key.LastIndexOf('.'); // 3
            var length = endIndex - startIndex; // 1
            var substring = x.Key.Substring(startIndex, length); // b
            return new KeyValuePair<string, string>(substring, x.Value);
        }

首先删除&amp;字符串列表中的最后一项

太阳哥哥 2025-02-17 20:49:51

我看到,当我在Storytriggers列表中仅添加1个元素时,它在检查员上看起来确实很奇怪,如问题所示。

但是,当我添加多个元素时,它会停止看起来很奇怪。这样我就可以使用它。

我认为这是Unity编辑器上的一个错误,因为怪异行为的条件在列表中的元素数量上。

编辑:

此后不久,我意识到,无论我添加多少个元素,第一个元素在扩展时总是看起来很奇怪(如问题所示)。尽管如此,与之合作并非不可能。我已经向Unity发送了一个错误报告。

I saw that when I add only 1 element to the StoryTriggers list it does look weird on the inspector like shown in the question.

But when I add multiple elements it stops looking weird. So I can work with it.

I assume this is a bug on the Unity Editor since the condition to the weird behavior is on the amount of elements on the list.

EDIT:

Soon after that, I realized that no matter how many elements I add to the list, the first one will always look weird when expanded (like shown in the question). Still, it is not something impossible to work with. I already sent a bug report to unity.

可序列化对象在检查员中看起来很奇怪

太阳哥哥 2025-02-17 01:01:11

.read()添加到第一个 loads 输入:

from json import loads
from collections import namedtuple
from os import path


class CamConfigurator:
    with open(path.join('utility', 'cam', 'configurator.json')) as __configFile:
        __configurator = loads(
            __configFile.read(), # <- there
            object_hook=lambda dictonary: namedtuple(
                'X', dictonary.keys()
            )(*dictonary.values())
        )
    camIndex = __configurator.availableCams[-1]
    pathToSnapshots = __configurator.pathToSnapshots

Add .read() to the first loads input:

from json import loads
from collections import namedtuple
from os import path


class CamConfigurator:
    with open(path.join('utility', 'cam', 'configurator.json')) as __configFile:
        __configurator = loads(
            __configFile.read(), # <- there
            object_hook=lambda dictonary: namedtuple(
                'X', dictonary.keys()
            )(*dictonary.values())
        )
    camIndex = __configurator.availableCams[-1]
    pathToSnapshots = __configurator.pathToSnapshots

将JSON文件映射到对象Python 2.7

更多

推荐作者

櫻之舞

文章 0 评论 0

弥枳

文章 0 评论 0

m2429

文章 0 评论 0

野却迷人

文章 0 评论 0

我怀念的。

文章 0 评论 0

更多

友情链接

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