我有以下15分钟的数据作为dataframe3年.前两列是索引.
2014-01-01 00:15:00 1269.6
2014-01-01 00:30:00 1161.6
2014-01-01 00:45:00 1466.4
2014-01-01 01:00:00 1365.6
2014-01-01 01:15:00 1362.6
2014-01-01 01:30:00 1064.0
2014-01-01 01:45:00 1171.2
2014-01-01 02:00:00 1171.0
2014-01-01 02:15:00 1330.4
2014-01-01 02:30:00 1309.6
2014-01-01 02:45:00 1308.4
2014-01-01 03:00:00 1494.0
Run Code Online (Sandbox Code Playgroud)
我曾经习惯于resample获得月平均值的第二个系列.
data_Monthly = data.resample('1M', how='mean')
Run Code Online (Sandbox Code Playgroud)
如何将最后一列中的值除以月平均值,结果仍然是15分钟粒度的时间序列?
我从.csv文件读入以下数据帧,其中"Date"列是索引.日期在行中,列显示当天的小时值.
> Date h1 h2 h3 h4 ... h24
> 14.03.2013 60 50 52 49 ... 73
Run Code Online (Sandbox Code Playgroud)
我想像这样安排它,这样就有一个索引列带有日期/时间,一列带有序列中的值
>Date/Time Value
>14.03.2013 00:00:00 60
>14.03.2013 01:00:00 50
>14.03.2013 02:00:00 52
>14.03.2013 03:00:00 49
>.
>.
>.
>14.03.2013 23:00:00 73
Run Code Online (Sandbox Code Playgroud)
我通过使用两个循环来遍历数据帧来尝试它.在熊猫中有更简单的方法吗?
几年来,我有以下格式的每小时数据帧:
Date/Time Value
01.03.2010 00:00:00 60
01.03.2010 01:00:00 50
01.03.2010 02:00:00 52
01.03.2010 03:00:00 49
.
.
.
31.12.2013 23:00:00 77
Run Code Online (Sandbox Code Playgroud)
我想平均数据,这样我就可以得到每年的0小时,1小时......小时23的平均值.
所以输出应该看起来像这样:
Year Hour Avg
2010 00 63
2010 01 55
2010 02 50
.
.
.
2013 22 71
2013 23 80
Run Code Online (Sandbox Code Playgroud)
有谁知道如何在熊猫中获得这个?
我想使用以下代码从Pandas数据帧生成Scatterplot:
df.plot.scatter(x='one', y='two, title='Scatterplot')
Run Code Online (Sandbox Code Playgroud)
是否有可以使用Statement发送的参数,因此它绘制了一个回归线并显示拟合的参数?
就像是:
df.plot.scatter(x='one', y='two', title='Scatterplot', Regression_line)
Run Code Online (Sandbox Code Playgroud) 我想通过简单地传递日期和时间来删除Python Dataframe中的一行.
Dataframe具有以下结构:
Date_Time Price1 Price2 Price3
2012-01-01 00:00:00 63.05 41.40 68.14
2012-01-01 01:00:00 68.20 42.44 59.64
2012-01-01 02:00:00 61.68 43.18 49.81
Run Code Online (Sandbox Code Playgroud)
我一直在努力 df = df.drop('2012-01-01 01:00:00')
但我不断收到以下错误消息:
exceptions.ValueError: labels [2012-01-01 01:00:00] not contained in axis
Run Code Online (Sandbox Code Playgroud)
任何有关删除行或只是删除值的帮助将非常感激.
:-)
我有以下 15 分钟的数据作为 3 年的数据框。前两列是索引。
2014-01-01 00:15:00 1269.6
2014-01-01 00:30:00 1161.6
2014-01-01 00:45:00 1466.4
2014-01-01 01:00:00 1365.6
2014-01-01 01:15:00 1362.6
2014-01-01 01:30:00 1064.0
2014-01-01 01:45:00 1171.2
2014-01-01 02:00:00 1171.0
2014-01-01 02:15:00 1330.4
2014-01-01 02:30:00 1309.6
2014-01-01 02:45:00 1308.4
2014-01-01 03:00:00 1494.0
Run Code Online (Sandbox Code Playgroud)
我想将数据抵消/转移到上一年,以便 2014-01-01 00:15:00 1269.6 将其转换为 2013-01-01 00:15:00 1269.6.
我已经使用 df = df.shift(-1, freq='15min') 将数据帧移至过去 15 分钟,但不希望偏移/移动 15 分钟间隔的数量,因为这可能会导致闰年和随着时钟的变化。
有人对此有一个顺利的解决方案吗?
我有一个df像这样分组的数据框:
Year Product Sales
2010 A 111
B 20
C 150
2011 A 10
B 28
C 190
… …
Run Code Online (Sandbox Code Playgroud)
我想将此绘制matplotlib为3d图表,其中Year以x为轴,Salesy轴Product为z轴。

我一直在尝试以下方法:
from mpl_toolkits.mplot3d import axes3d
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
X = dfgrouped['Year']
Y = dfgrouped['Sales']
Z = dfgrouped['Product']
ax.bar(X, Y, Z, color=cs, alpha=0.8)
Run Code Online (Sandbox Code Playgroud)
不幸的是我越来越
“ ValueError:大小不兼容:参数'height'必须为长度7或标量”
我正在尝试运行sklearn.metrics.classification_report,我的数据在Pandas数据帧中.数据框df_joined看起来像这样,有100行:
Timestamp Label Pred
2016-10-05 29.75 30.781430
2016-10-06 30.35 31.379146
2016-10-07 31.59 31.174824
2017-02-13 29.63 29.875497
2017-02-14 29.60 29.923161
2017-02-15 30.22 30.257284
2017-02-16 30.12 30.374257
2017-02-17 30.09 30.357196
2017-02-20 31.03 30.971070
2017-02-21 31.05 30.930189
Run Code Online (Sandbox Code Playgroud)
我现在正在尝试打印classification_report
print 'Classification Report:', '\n', sklearn.metrics.classification_report(df_joined[label],df_joined['Pred'] )
Run Code Online (Sandbox Code Playgroud)
我收到错误:
文件"\ Python\WinPython-32bit-2.7.10.3\python-2.7.10\lib\site-packages\sklearn\utils\multiclass.py",第106行,在unique_labels中引发ValueError("未知标签类型:%r" %ys)
TypeError:并非在字符串格式化期间转换所有参数
我一直试图使用,sklearn.metrics.classification_report(df_joined[label].values, df_joined['Pred'].values)但它产生相同的错误.
有人知道这是从哪里来的?
我从yahoo finance下载了每日数据
Open High Low Close Volume \
Date
2016-01-04 10485.809570 10485.910156 10248.580078 10283.440430 116249000
2016-01-05 10373.269531 10384.259766 10173.519531 10310.099609 82348000
2016-01-06 10288.679688 10288.679688 10094.179688 10214.019531 87751700
2016-01-07 10144.169922 10145.469727 9810.469727 9979.849609 124188100
2016-01-08 10010.469727 10122.459961 9849.339844 9849.339844 95672200
...
2016-02-23 9503.120117 9535.120117 9405.219727 9416.769531 87240700
2016-02-24 9396.480469 9415.330078 9125.190430 9167.799805 99216000
2016-02-25 9277.019531 9391.309570 9199.089844 9331.480469 0
2016-02-26 9454.519531 9576.879883 9436.330078 9513.299805 95662100
2016-02-29 9424.929688 9498.570312 9332.419922 9495.400391 90978700
Run Code Online (Sandbox Code Playgroud)
我想找到每个月的最高收盘价以及收盘价的日期.
使用groupby,dfM = df['Close'].groupby(df.index.month).max()它会返回每月最大值,但我会丢失每日索引位置.
grouped by month
1 …Run Code Online (Sandbox Code Playgroud) pandas ×9
python ×6
time-series ×4
average ×2
dataframe ×2
3d ×1
datetime ×1
delete-row ×1
group-by ×1
indexing ×1
matplotlib ×1
max ×1
offset ×1
python-2.7 ×1
regression ×1
resampling ×1
row ×1
scatter-plot ×1
scikit-learn ×1
seaborn ×1
sequence ×1
statistics ×1