更简单的方法来创建熊猫多列数据框?(Easier way to create pandas multi-column Dataframe?)
现在我创建一个多列DataFrame ,如下所示:
column1 = ["A","B","C"] column2 = ["a","b","c"] tuples = [] for c1 in column1: for c2 in column2: tuples += [(i1,i2)] columns = pd.MultiIndex.from_tuples(tuples, names=['Large index', 'Small index']) q = pd.DataFrame(index = t, columns = columns ) q.loc[:, ("A","a")] = 1
现在我想知道:是否有更简单的语法来提供相同的内容? 干杯!
编辑:更正了错别字。
Right now I create a multi-column DataFrame as following:
column1 = ["A","B","C"] column2 = ["a","b","c"] tuples = [] for c1 in column1: for c2 in column2: tuples += [(i1,i2)] columns = pd.MultiIndex.from_tuples(tuples, names=['Large index', 'Small index']) q = pd.DataFrame(index = t, columns = columns ) q.loc[:, ("A","a")] = 1
Now I wonder: Is there an easier syntax to deliver the same? Cheers!
edit: Corrected typos.
原文:https://stackoverflow.com/questions/48099934
更新时间:2022-01-06 08:01
最满意答案
Apparently it's a known issue.
As it is now function instances properties are type
any
even if they're undefined. :(My issue was closed as duplicate. This explains the problem in my question.
相关问答
更多-
我所做的只是注释函数本身 const getForecastHourly = (query: number): ActionType => ({ /* - */ }); 因为flow知道const ,它知道值不能改变并且会自己计算出类型。 另一方面,如果你使用let ,那么我也会对变量本身进行注释,因此如果值具有正确的类型,则flow可以检查重新分配值。 What I do is only annotate the function itself like const getForecastHourly ...
-
显然这是一个已知的问题 。 因为它现在是函数实例属性, any即使它们未定义,也是可以输入的。 :( 我的问题被重复关闭。 这解释了我的问题中的问题。 Apparently it's a known issue. As it is now function instances properties are type any even if they're undefined. :( My issue was closed as duplicate. This explains the problem in ...
-
您可以指定构造函数依赖关系并告诉结构映射哪个命名参数应该具有哪个依赖关系: For
.Use () .Ctor ("alphaPolicy").Is () .Ctor ("numericPolicy").Is (); You can specify constructor dependencies and tell structure map which ... -
我怀疑你想要将Map
更改为Map 在ClassA构造函数签名(和字段)中Map 。 否则, HashMap 实际上不是它的有效参数。 考虑哪些操作在Map - 你可以写: map.put("foo", new SomeArbitraryImplementatio ... -
当提出这个问题时,内置的lib文件确实优先于任何用户lib文件,并且没有办法覆盖它们。 从Flow v0.19.0 (2015年12月1日发布)开始,您现在可以覆盖内置库。 从最高到最低的优先顺序如下: 使用--lib指定的Lib文件 在.flowconfig的[libs]部分中指定的Lib文件 内置库 When this question was posed, the builtin lib files did take precedence over any user lib files and the ...
-
真的,这没什么大不了的。 您通过引用传递给const ,并且要传递对非const的引用,您需要调用者写入ref(x) 。 而不是定义无数版本,您可以一劳永逸地定义支持ArgPack模板 。 或者,使用C ++ 0xpurrfectführwarding。 干杯&hth。, It's no big deal, really. You pass by reference to const, and where a reference to non-const is to be passed you requir ...
-
不,我不相信这是可能的。 需要在顶层定义类型。 我做的是这样的: export type TodoTy = ... 然后我需要在另一个模块中使用它,做到 import type {TodoTy} from ... 我知道这可能不像保持类型更接近于使用它们的位置那样可口,但在实践中它对我来说很好。 No, I don't believe this is possible. Types need to be defined at the top-level. What I do is something lik ...
-
好吧,你可以使用例如getConstructor(Class...)来获得一个非默认无参数的构造函数。 你有这样的事情: import java.lang.reflect.*; public class Handler { private E instanceOfE = ...; // Not sure where you get the E from. private Constructor ctor; public Handle ...
-
Typescript不检查接口声明的函数参数类型(Typescript not checking function argument types declared by interfaces)[2022-10-15]
这在TypeScript FAQ中得到了解答 。 这是答案的文字: 这是预期和期望的行为。 首先,请参阅FAQ顶部的“替代性”入门 - handler是callback的有效参数,因为它可以安全地忽略额外的参数。 其次,让我们考虑另一个案例: let items = [1, 2, 3]; items.forEach(arg => console.log(arg)); 这与“想要”错误的示例是同构的。 在运行时, forEach使用三个参数(值,索引,数组)调用给定的回调,但大多数情况下回调仅使用一个或两个 ... -
问题在于,如果要限制给定属性的类,MATLAB需要为该属性(该类的属性)创建一个默认空值,因此必须能够成功调用empty方法( Core.Modularity.AbsClass.empty() ),但由于它是一个抽象类,这是不可能的。 试图这样做会导致此错误: 限制属性值的类时,必须将该属性限制为具体类。 在类'MyClass'中的属性'DataModule'的定义中替换抽象类'Core.Modularity.AbsBase'。 从技术上讲, 你可以使用旧的(和未记录的)语法来限制属性的类,显然它可以工作 ...