我想要一个25小时偏移的熊猫时期范围,我看到有两种方法可以做到这一点(见这里):
第一种方法是使用freq=25H,我尝试过,并给了我正确的答案:
import pandas as pd
pd.period_range(start='2016-01-01 10:00', freq = '25H', periods = 10)
Run Code Online (Sandbox Code Playgroud)
结果是
PeriodIndex(['2016-01-01 10:00', '2016-01-02 11:00', '2016-01-03 12:00',
'2016-01-04 13:00', '2016-01-05 14:00', '2016-01-06 15:00',
'2016-01-07 16:00', '2016-01-08 17:00', '2016-01-09 18:00',
'2016-01-10 19:00'],
dtype='int64', freq='25H')
Run Code Online (Sandbox Code Playgroud)
freq=1D1H然而,第二种方式使用了一个相当奇怪的结果:
pd.period_range(start='2016-01-01 10:00', freq = '1D1H', periods = 10)
Run Code Online (Sandbox Code Playgroud)
我得到了
PeriodIndex(['1971-12-02 01:00', '1971-12-02 02:00', '1971-12-02 03:00',
'1971-12-02 04:00', '1971-12-02 05:00', '1971-12-02 06:00',
'1971-12-02 07:00', '1971-12-02 08:00', '1971-12-02 09:00',
'1971-12-02 10:00'],
dtype='int64', freq='25H')
Run Code Online (Sandbox Code Playgroud)
那么也许1D1H不是指定频率的有效方法?怎么回事1971?(我也尝试使用1D1H …
假设我有一个包含一些变量名的本地宏
local indep "cat dog pig"
Run Code Online (Sandbox Code Playgroud)
pig如果我希望宏仅包含catand ,如何从宏中删除dog?
在Python库中Statsmodels,您可以打印出回归结果print(results.summary()),如何在一个表中打印出多个回归的摘要,以便更好地进行比较?
线性回归,代码取自statsmodels文档:
nsample = 100
x = np.linspace(0, 10, 100)
X = np.column_stack((x, x**2))
beta = np.array([0.1, 10])
e = np.random.normal(size=nsample)
y = np.dot(X, beta) + e
model = sm.OLS(y, X)
results_noconstant = model.fit()
Run Code Online (Sandbox Code Playgroud)
然后我向模型添加一个常量并再次运行回归:
beta = np.array([1, 0.1, 10])
X = sm.add_constant(X)
y = np.dot(X, beta) + e
model = sm.OLS(y, X)
results_withconstant = model.fit()
Run Code Online (Sandbox Code Playgroud)
我想在一张桌子上看到摘要results_noconstant并results_withconstant打印出来.这应该是一个非常有用的功能,但我没有在statsmodels文档中找到任何关于此的说明.
编辑:我想到的回归表将是这样的,我想知道是否有现成的功能来做到这一点.
我在文档中读到可以多层构图,但是以某种方式将数据集中到输出图中,并在所有构面中重复。
我可以毫不费力地对每一层进行操作,这是cars数据集的示例:
import altair as alt
from altair import datum
from vega_datasets import data
cars = data.cars()
horse = alt.Chart(cars).mark_point().encode(
x = 'Weight_in_lbs',
y = 'Horsepower'
)
chart = alt.hconcat()
for origin in cars.Origin.unique():
chart |= horse.transform_filter(datum.Origin == origin).properties(title=origin)
chart
Run Code Online (Sandbox Code Playgroud)
miles = alt.Chart(cars).mark_point(color='red').encode(
x = 'Weight_in_lbs',
y = 'Miles_per_Gallon'
)
chart = alt.hconcat()
for origin in cars.Origin.unique():
chart |= miles.transform_filter(datum.Origin == origin).properties(title=origin)
chart
Run Code Online (Sandbox Code Playgroud)
但是合并后所有数据都会显示在每个图上
combined = horse + miles
chart = alt.hconcat()
for origin in cars.Origin.unique(): …Run Code Online (Sandbox Code Playgroud)