我在以下路径的Windows机器上运行python:
C:\WinPython-64bit-3.4.4.1
Run Code Online (Sandbox Code Playgroud)
我正在尝试升级到最新版本的pandas(目前正在运行'0.17.1'),但我遇到了问题.
我查看过以前的帖子,并尝试使用命令行:
c:/>pip install --upgrade pandas
Run Code Online (Sandbox Code Playgroud)
但只是得到了 'pip is not recognised as an internal or external command, operable program or batch file'
任何帮助将非常感激.
谢谢
我有2个DataFrames
我想合并.我查看了文档并尝试执行以下操作,但对如何操作感到困惑.就像我说我有2 DataFrames
:
df1:
id name type currency
0 BTA.S Applewood Hard GBp
1 VOD.S Softwood Soft GBp
Run Code Online (Sandbox Code Playgroud)
和
df2:
id
BTA.S 301.221525
VOD.S 213.791400
Run Code Online (Sandbox Code Playgroud)
我想回来:
id name type currency price
0 BTA.S Applewood Hard GBp 301.221525
1 VOD.S Softwood Soft GBp 213.791400
Run Code Online (Sandbox Code Playgroud)
其中df2的price列与df1合并.(只是为了让你知道,在我完成的时候会有更多的木材类型).
我尝试了几种方法:
Result = df1.merge(df2[['*.S']], left_on='id', right_index=True)
Run Code Online (Sandbox Code Playgroud)
我遇到异常的地方:
ValueError: can not merge DataFrame with instance of type <class 'pandas.core.series.Series'>
Run Code Online (Sandbox Code Playgroud)
和
Result = pd.concat([Df1, Df2], axis=1, ignore_index=True)
Run Code Online (Sandbox Code Playgroud)
在哪里我得到例外:
ValueError: labels ['type'] not contained in axis
Run Code Online (Sandbox Code Playgroud)
但我感到困惑.对不起,如果这是一个基本问题.任何帮助将非常感激.非常感谢
我有2个产品的示例数据帧(df):
BBG.XAMS.FUR.S BBG.XAMS.MT.S
date
2014-10-23 -2368.850388 0.000000
2014-10-24 6043.456178 0.000000
2015-03-23 -0.674996 -0.674997
2015-03-24 82.704951 11.868748
2015-03-25 -11.027327 84.160210
Run Code Online (Sandbox Code Playgroud)
有没有办法只检索数据帧的最后一个索引值.所以在这个例子中我需要检索的日期值是2015-03-25?
非常感谢
我试图使用以下语句选择并修剪表中的所有条目:
SELECT TRIM(*) FROM TABLE
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误.有没有办法返回所有选中的条目,以便在每个字符串的开头和结尾处为空白字符修剪它们?
我是 Linux 新手,我有一个名为stacey
. 我怎样才能从中创建一个压缩的 tarball?
我可以用 tar 压缩该文件夹tar -cvzf stacey.tar *
。但是我可以同时添加 7zip,这样我就有一个名为 的压缩 tarball 吗stacey.tar.gz
?
我试图将数据帧中的所有值加总为一个数字.
例如,使用数据帧
BBG.XAMS.FUR.S_pnl_pos_cost BBG.XAMS.MT.S_pnl_pos_cost
date
2015-03-23 -0.674996 -0.674997
2015-03-24 82.704951 11.868748
2015-03-25 -11.027327 84.160210
2015-03-26 228.426675 -131.901556
2015-03-27 -99.744986 214.579858
Run Code Online (Sandbox Code Playgroud)
我想要返回值377.71658.
我尝试过df.sum(),但只按列进行求和.
任何帮助将非常感激.
我有一个数据帧(df),看起来像:
date A
2001-01-02 1.0022
2001-01-03 1.1033
2001-01-04 1.1496
2001-01-05 1.1033
2015-03-30 126.3700
2015-03-31 124.4300
2015-04-01 124.2500
2015-04-02 124.8900
Run Code Online (Sandbox Code Playgroud)
对于整个时间序列,我试图将今天的值除以昨天,并使用以下内容记录结果:
df["B"] = math.log(df["A"] / df["A"].shift(1))
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:
TypeError: cannot convert the series to <class 'float'>
Run Code Online (Sandbox Code Playgroud)
有人能让我知道如何解决这个问题吗?我试图使用以下方式转换为float:
df["B"] .astype(float)
Run Code Online (Sandbox Code Playgroud)
但无法得到任何工作.任何指导都将非常感谢.
谢谢
我有一个名为staticData的数据框,看起来像这样:
narrow_sector broad_sector country exchange \
unique_id
BBG.MTAA.STM.S Semiconductors Technology CH MTAA
BBG.MTAA.CNHI.S Machinery-Diversified Industrial GB MTAA
BBG.MTAA.FCA.S Auto Manufacturers Consumer Cyclical GB MTAA
BBG.MTAA.A2A.S Electric Utilities IT MTAA
BBG.MTAA.ACE.S Electric Utilities IT MTAA
Run Code Online (Sandbox Code Playgroud)
我正试图逐行遍历数据帧,以选择索引(unique_id)和交换的两位信息。我在遍历索引时遇到问题。请查看我的代码:
for i, row in staticData.iterrows():
unique_id = staticData.ix[i]
exchange = row['exchange']
Run Code Online (Sandbox Code Playgroud)
我已经尝试过unique_id = row ['unique_id'],但无法使其正常工作...
我正在尝试返回第1行的发言
unique_id = BBG.MTAA.STM.S
exchange = MTAA
Run Code Online (Sandbox Code Playgroud) 我从来没有更新我的Scipy版本并且想要.我正在运行WinPython-64bit-3.4.4.1.如果有人能指出我更新我的Scipy的正确方法,我将非常感激.请假设我不知道如何更新版本.
谢谢
我有一个数据框df
,其中包含以下列数据标题:
date A B C D E F G H I
07/03/2016 2.08 1 NaN NaN 1029 2 2.65 4861688 -0.0388
08/03/2016 2.20 1 NaN NaN 1089 2 2.20 5770819 -0.0447
: :
09/03/2016 2.14 1 NaN NaN 1059 2 2.01 5547959 -0.0514
10/03/2016 2.25 1 NaN NaN 1089 2 1.95 4064482 -0.0520
Run Code Online (Sandbox Code Playgroud)
有没有办法改变列的顺序,以便将列F移动到列H之后的位置.结果df
将如下所示:
date A B C D E F G H F I
07/03/2016 2.08 1 NaN NaN 1029 2 2.65 4861688 2 -0.0388 …
Run Code Online (Sandbox Code Playgroud)