我有两个清单:
“max_”由日期时间类型组成:
2012-04-20 00:00:00
2012-11-29 00:00:00
2013-11-22 00:00:00
“min_”,由datetimeindex:
组成DatetimeIndex(['2012-07-11'], dtype='datetime64[ns]', name=u'Date', freq=None)
DatetimeIndex(['2013-02-05', '2013-10-23'], dtype='datetime64[ns]', name=u'Date', freq=None)
DatetimeIndex([], dtype='datetime64[ns]', name=u'Date', freq=None)
我的预期输出是从每个最大值到其相应的最小值的范围,例如,第一个将是范围(2012-04-20至2012-07-11)。我试过了:
pd.date_range(max_, min_)
TypeError: Cannot convert input [DatetimeIndex(['2012-07-11'], dtype='datetime64[ns]', name=u'Date', freq=None)] of type <class 'pandas.core.indexes.datetimes.DatetimeIndex'> to Timestamp
我不确定如何绕过转换部分,另外,我想只有min_列表的第一个值(并忽略任何其他值)。
答案 0 :(得分:0)
我认为您只需在列表中指定要创建范围的项目:
from sklearn.preprocessing import PolynomialFeatures
import numpy as np
from sympy import *
# nb monomials (n+d,d), d=degree, n=# of inputs
def check(n,d,user_array=None):
if user_array is None:
x = np.arange(2,2+n).reshape(1,n) # e.g. array([[2, 3]])
else:
x = user_array.reshape(1,n)
#x = np.arange(2,2+n).reshape(1,n) # e.g. array([[2, 3]])
print('x = ', x)
##
poly_feat = PolynomialFeatures(d)
x_poly_feat = poly_feat.fit_transform(x)
##
x_poly_feat_list = [ int(i) for i in x_poly_feat[0]]
#print('x_poly_feat = ', x_poly_feat)
#print('x_poly_feat = ', list(x_poly_feat[0]))
print('x_poly_feat_list = ', x_poly_feat_list)
return x_poly_feat_list
def check_sympy_degree():
x3,x2,x1 = symbols('x3 x2 x1')
poly = Poly( 125*x3**3 + 75*x2*x3**2 + 45*x2**2*x3 + 27*x2**3 + 50*x1*x3**2 + 30*x1*x2*x3 + 18*x1*x2**2 + 20*x1**2*x3 + 12*x1**2*x2
+ 8*x1**3 + 25*x3**2 + 15*x2*x3 + 9*x2**2 + 10*x1*x3 + 6*x1*x2 + 4*x1**2 + 2*x1 + 3*x2 + 5*x3 + 1,(x3,x2,x1) )
c_grevlex = poly.coeffs(order='grevlex')
c_grlex = poly.coeffs(order='grlex')
print('poly = ',poly)
print('c_grevlex = ', c_grevlex[::-1])
print('c_grlex = ', c_grlex[::-1])
return c_grlex, c_grevlex
if __name__ == '__main__':
#check(n=2,d=3)
##
x_poly_feat_list = check(n=3,d=3,user_array=np.array([2,3,5]))
##
c_grlex, c_grevlex = check_sympy_degree()
print('len(c_grlex)',len(c_grlex))
print('len(c_grevlex)',len(c_grevlex))
print('len(x_poly_feat_list)',len(x_poly_feat_list))
all_match_grlex = all( c_grlex[i] == x_poly_feat_list for i in range(len(x_poly_feat_list)) )
all_match_grevlex = all( c_grevlex[i] == x_poly_feat_list for i in range(len(x_poly_feat_list)) )
print('all_match_grlex = ',all_match_grlex)
print('all_match_grevlex = ',all_match_grevlex)
如果您要打印范围:
pd.date_range(min_[0],max_[0])