草庐IT

Time-series

全部标签

python - 结合 Pandas 中的两个时间序列

如果这明显记录在某处,我深表歉意,但我很难发现它。我有两个具有一些重叠日期/索引的TimeSeries,我想合并它们。我假设我必须指定从两个系列中的哪一个系列中获取重叠日期的值。为了说明,我有:s1:2008-09-151002008-10-15101s2:2008-10-15101.012008-11-15102.02我想要:s3:2008-09-151002008-10-151012008-11-15102.02或s3:2008-09-151002008-10-15101.012008-11-15102.02 最佳答案 这可以通

python - 从 pandas.Series 中选择局部最小值和最大值

有一个scipy.signal.argrelextrema与ndarray一起使用的函数,但是当我尝试在pandas.Series上使用它时,它返回错误。将它与pandas一起使用的正确方法是什么?importnumpyasnpimportpandasaspdfromscipy.signalimportargrelextremas=pd.Series(randn(10),range(10))sargrelextrema(s,np.greater)-----------------------------------------------------------------------

python - 将 pandas.core.series.Series 转换为具有适当列值的数据框 python

我正在运行一个变量为pandas.core.series.Series类型的函数。typeoftheseriesshownbelow.product_id_y1159730count1Name:6159402,dtype:object我想把它转换成一个数据框,这样,我得到product_id_ycount11597301我试过这样做:series1=series1.to_frame()结果不对转换为dataframe之后6159402product_id_y1159730count1在重置索引后,我series1=series1.reset_index()index61594020pr

python - 计算 DataFrame 每一行中 Series 中项目的出现次数

我有一个看起来像这样的pandas.DataFrame。COL1COL2COL3C1NoneNoneC1C2NoneC1C1NoneC1C2C3对于此数据框中的每一行,我想计算每个C1、C2、C3的出现次数,并将此信息作为列附加到此数据框中。例如,第一行有1个C1、0个C2和0个C3。最终的数据框应该是这样的COL1COL2COL3C1C2C3C1NoneNone100C1C2None110C1C1None200C1C2C3111因此,我创建了一个以C1、C2和C3作为值的系列-topcount的一种方法是遍历DataFrame的行和列,然后遍历该系列并在匹配时递增计数器。但是是否有一

python - App Engine : Is time. sleep() 计入我的配额?

嘿。我正在开发一个AppEngine应用程序,该应用程序涉及对GoogleMapsAPI的查询以进行地理编码。Googlemap不喜欢太多请求,因此我使用time.sleep(1)在每个请求之间设置了1秒的延迟。我注意到我的GAE仪表板中的配额不足,因此决定运行一个简短的测试:importcProfileimporttimedeffoo():time.sleep(3)cProfile.run('foo()')这给了我以下输出:4functioncallsin3.003CPUsecondsOrderedby:standardnamencallstottimepercallcumtimep

python - AttributeError : module object has no attribute "Series". 代码在 iPython 中有效

子模块不是隐式导入的,必须显式声明,但我正在显式调用pd.Series子模块,不是吗?无论如何,importpandasaspd难道不应该允许调用pd.Series吗?以下代码在iPython中完美运行,但在从脚本执行时失败。#!/usr/bin/env/python2.7#-*-coding:utf-8-*-importpandasaspdimportnumpyasnpcounts=pd.Series([632,1638,569,115],index=["Firmicutes","Proteobacteria","Actinobacteria","Bacteroidetes"])结果

python - 如何获取 pandas.Series 或 pandas.DataFrame 中第 i 个项目的索引?

我正在尝试获取我拥有的Series中第6项的索引。这是头部的样子:UnitedStates1.536434e+13China6.348609e+12Japan5.542208e+12Germany3.493025e+12France2.681725e+12为了获取第6个索引名称(排序后的第6个国家/地区),我通常使用s.head(6)并从那里获取第6个索引。s.head(6)给我:UnitedStates1.536434e+13China6.348609e+12Japan5.542208e+12Germany3.493025e+12France2.681725e+12UnitedKin

python - python statsmodels.tsa.seasonal 中的值错误

我有这个带有日期时间索引的数据框:ts_log:dateprice_per_unit2013-04-0412.7623692013-04-0512.7771202013-04-0612.7731462013-04-0712.7807742013-04-0812.786835我有这段代码用于分解fromstatsmodels.tsa.seasonalimportseasonal_decomposedecomposition=seasonal_decompose(ts_log)trend=decomposition.trendseasonal=decomposition.seasonalr

python - 在 Python 中,time() 返回的纪元时间是否始终从 1970 年 1 月 1 日开始计算?

Python中的纪元开始时间是否独立于平台(即始终为1/1/1970)?还是平台依赖?我想在运行Python的各种机器上序列化日期时间(精度为秒),并能够在不同的平台上读取它们,可能还使用不同的编程语言(而不是Python)。序列化纪元时间是个好主意吗? 最佳答案 Thedocumentation说:Tofindoutwhattheepochis,lookatgmtime(0).我会把这解释为没有特定的时代是有保证的。另见thisPython-Devthread.这似乎证实了这样一种观念,即在实践中,纪元始终假定为1970/01/0

python - 为什么找不到 Python datetime time delta?

我正在尝试以mmddyyyy格式制作一组日期。日期将从当天开始,然后到future两周。所以这一切都取决于开始日期。当我运行我的代码时,我收到一条错误消息:Traceback(mostrecentcalllast):File"timeTest.py",line8,inday=datetime.timedelta(days=i)AttributeError:typeobject'datetime.datetime'hasnoattribute'timedelta'我不确定为什么会这样,因为在网上搜索后,我注意到人们以这种方式使用“timedelta”。这是我的代码:importtimef