- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在尝试合并 (Pandas 14.1) 数据框和系列。系列应该形成一个新列,带有一些 NA(因为系列的索引值是数据帧的索引值的子集)。
这适用于玩具示例,但不适用于我的数据(详情如下)。
例子:
import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.randn(6, 4), columns=['A', 'B', 'C', 'D'], index=pd.date_range('1/1/2011', periods=6, freq='D'))
df1
A B C D
2011-01-01 -0.487926 0.439190 0.194810 0.333896
2011-01-02 1.708024 0.237587 -0.958100 1.418285
2011-01-03 -1.228805 1.266068 -1.755050 -1.476395
2011-01-04 -0.554705 1.342504 0.245934 0.955521
2011-01-05 -0.351260 -0.798270 0.820535 -0.597322
2011-01-06 0.132924 0.501027 -1.139487 1.107873
s1 = pd.Series(np.random.randn(3), name='foo', index=pd.date_range('1/1/2011', periods=3, freq='2D'))
s1
2011-01-01 -1.660578
2011-01-03 -0.209688
2011-01-05 0.546146
Freq: 2D, Name: foo, dtype: float64
pd.concat([df1, s1],axis=1)
A B C D foo
2011-01-01 -0.487926 0.439190 0.194810 0.333896 -1.660578
2011-01-02 1.708024 0.237587 -0.958100 1.418285 NaN
2011-01-03 -1.228805 1.266068 -1.755050 -1.476395 -0.209688
2011-01-04 -0.554705 1.342504 0.245934 0.955521 NaN
2011-01-05 -0.351260 -0.798270 0.820535 -0.597322 0.546146
2011-01-06 0.132924 0.501027 -1.139487 1.107873 NaN
数据的情况(见下文)似乎基本相同 - 将系列与 DatetimeIndex 连接,其值是数据帧的子集。但它在标题中给出了 ValueError (blah1 = (5, 286) blah2 = (5, 276) )。为什么它不起作用?:
In[187]: df.head()
Out[188]:
high low loc_h loc_l
time
2014-01-01 17:00:00 1.376235 1.375945 1.376235 1.375945
2014-01-01 17:01:00 1.376005 1.375775 NaN NaN
2014-01-01 17:02:00 1.375795 1.375445 NaN 1.375445
2014-01-01 17:03:00 1.375625 1.375515 NaN NaN
2014-01-01 17:04:00 1.375585 1.375585 NaN NaN
In [186]: df.index
Out[186]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-01-01 17:00:00, ..., 2014-01-01 21:30:00]
Length: 271, Freq: None, Timezone: None
In [189]: hl.head()
Out[189]:
2014-01-01 17:00:00 1.376090
2014-01-01 17:02:00 1.375445
2014-01-01 17:05:00 1.376195
2014-01-01 17:10:00 1.375385
2014-01-01 17:12:00 1.376115
dtype: float64
In [187]:hl.index
Out[187]:
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-01-01 17:00:00, ..., 2014-01-01 21:30:00]
Length: 89, Freq: None, Timezone: None
In: pd.concat([df, hl], axis=1)
Out: [stack trace] ValueError: Shape of passed values is (5, 286), indices imply (5, 276)
最佳答案
我遇到了类似的问题(join
有效,但 concat
失败)。
检查 df1
和 s1
中的重复索引值(例如 df1.index.is_unique
)
删除重复的索引值(例如,df.drop_duplicates(inplace=True)
)或此处的方法之一 https://stackoverflow.com/a/34297689/7163376应该解决它。
关于python - Pandas concat : ValueError: Shape of passed values is blah, 索引暗示 blah2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27719407/
数据库设置: http://sqlfiddle.com/#!2/4d1c2/1 以下查询选择属于productID的所有标签及其位置,逗号分隔: SELECT CONCAT_WS(',', GROUP
要连接两个文件,它看起来像这样: concat: { src: ['common.js','js/app.js'], dest: 'assets/js/app.js' } 如果
我有一个执行 SQL 脚本的 PDI(Kettle)转换,脚本的输出是一列,如下所示: val1 val2 val3 val4 "more values"... 我需要像这样在一个 Excel 单元格
我正在尝试传递一个参数 [例如@X nvarchar(MAX)] 转换成变量 [例如@message nvarchar(MAX)] 在存储过程中。该变量使用 CONCAT 组合字符串值和变量,它最终成
我不知道如何解释我的问题... 这是我的sql请求: SELECT DISTINCT CONCAT (nompropre, ' ', Auteur, ' de ', localite) AS aute
如何在与另一个表连接的表中使用 concat 和 group concat。架构如下所示: 第一表: MariaDB [ittresnamuda]> select * from tb_tipe_req
在我的 CREATE VIEW 中,我想: SELECT CONCAT( t.str1, t.str2 ) AS Title, CHAR_LENGTH( Title ) AS Length 但这会产生
我正在使用 CriteriaBuilder.concat 连接 2 个字符串,代码如下: Expression concat = criteriaBuilder.concat(expr1, expr2
我有以下继承 IEnumerable 的类 public class LinesEnumerable : IEnumerable { protected readonly IPointSeri
_.concat 和有什么区别lodash 和 Array.prototype.concat() ?. 最佳答案 欢迎来到 Stackoverflow! 这些函数的工作方式相同,但语法不同: _.co
我有一个非常大的表(几百万条记录)。表中的列 A 目前是这样的:id、道路名称、纬度、经度,其中 id 是自动增量 PK。 目前,1 个道路名称可以在表中包含多个条目,因为每条道路都映射到多个(纬度、
我测试了各种数组连接技术,并不是因为它实际上对我的代码很重要,而只是顺便说一句,看看我们现在在哪里。正如预期的那样,非常新的 ES 2015 传播运算符在 JavaScript 数组上被旧的 conc
我有一个数组,我需要使用一些编辑重新编译。我是在 async.concat() 的帮助下完成的,但有些东西不起作用。告诉我,哪里错了? async.concat(dialogs, function(d
在 JavaScript 中,我遇到过以两种主要方式编写的代码,用于连接两个(或更多)使用 .concat() 的数组。 Array 上的方法目的。 (假设在下文中,arr1 和 arr2 是作为 .
我之前曾使用 stack over flow 来解决我的 sql 问题并且成功了。 这一次我的下一期可能不会那么成功。 我有一个名为 Statements_1 的表,该表大约有 50 列,假设有 10
我在想以一种相当奇怪的方式从数据库获取东西时遇到了一些麻烦。假设我有下一张 table ID | Rating 229 | 3 229 | 2 229 | 4 229 | 2 2
我有类似表中的内容 mysql> select uuid , short-uuid FROM sampleUUID WHERE identifier ="test123"; +------------
我有一个查询,用于获取我离开加入两个表的帖子: 类别和标签:LEFT JOIN 到链接表→‖INNER JOIN 到类别和标签名称表。 LEFT JOIN wp_term_relationships
我目前正在开发一个大型 angular.js 项目。我使用 grunt 将所有文件合并/丑化为一个大的 target.js 文件,然后将其包含在索引页中。 我已经意识到,这使得在开发环境中调试变得非常
我的表中有三列:firstName、lastName 和 jobTitle。我想将 firstName 和 lastName 连接为 Fullname,然后连接 Fullname 和 jobTitle
我是一名优秀的程序员,十分优秀!