我想从csv创建的pandas数据框创建一个类。使用@staticmethod是最好的方法吗?这样我就不必分别读取每个对象的数据帧
我如何摆脱下面的图中使用python matplotlib中的foll命令制作的灰色背景
ax.bar(x_axis,bar_val,yerr=err_val,linewidth=0,width=0.2)
Run Code Online (Sandbox Code Playgroud)

我正在使用sympy解决b1和b2:
y=x/[x+exp(b1-b2*x)]
x1 = 90; y1 = 0.05 and x2=99;y2=0.95
import sympy
b1,b2 = symbols('b1 b2')
solve([Eq(90*0.05+90*exp(b1-(b2*90))-90, 0.0), Eq(99*0.95+99*exp(b1-(b2*99))-99, 0.0)], [b1, b2])
Run Code Online (Sandbox Code Playgroud)
>>> {b1:29.3930964972769,b2:0.327159886574049}
Run Code Online (Sandbox Code Playgroud)
如何使用这些结果绘制受这些值约束的S形曲线。Y轴的范围是0到1。x1,y1和x2,y2是该曲线上的2个点。
Y2010 Y2011 Y2012 Y2013 test
0 86574 77806 93476 99626 2
1 60954 67873 65135 64418 4
2 156 575 280 330 6
3 1435 1360 1406 1956 7
4 3818 7700 6900 5500 8
Run Code Online (Sandbox Code Playgroud)
有没有办法将此数据框的列从Y2010 ...重命名为2010 ..即删除初始的'Y'.我想使用正则表达式,因为我有很多这样的列.我试过这个:
df.rename(df.filter(regex='^Y\d{4}').columns.values, range(2010, 2013 + 1, 1))
Run Code Online (Sandbox Code Playgroud)
--EDIT:数据帧的包含不以'Y'开头的列
我有以下数据帧:
datetime JD YEAR VAL
2000-01-01 1 2000 0.5
2000-01-02 2 2000 1.2
2000-01-03 3 2000 2.1
2000-01-04 4 2000 3.4
2000-01-05 5 2000 4.6
2000-01-06 6 2000 6.8
2000-01-07 7 2000 7.2
2000-01-08 8 2000 0.2
2000-01-09 9 2000 0.9
...
2010-12-31 365 2014 4.1
Run Code Online (Sandbox Code Playgroud)
第一年是2000年,去年是2010年.没有闰年(即没有对应于2月29日的行),datetime是索引列.
我想计算一个新的数据帧,从2010年1月1日到2010年12月31日.我希望它包含一个列,用于计算由10个值组成的数组中的2010年1月1日值(VAL)的百分位数(2000年1月1日) ,2001年1月1日... 2009年1月1日).同样,2010年1月2日与前几年的1月2日进行了比较....
lyr = df.YEAR.max() # last year i.e. 2010
cdf = df[df.YEAR == lyr]# Latest year dataframe
pdf = df[df.index.year < lyr] # Previous years dataframe
pdf.groupby('JD')['VAL']
stats.percentileofscore(pdf['VAL'], cdf['VAL'])
Run Code Online (Sandbox Code Playgroud)
但是,我不知道如何使代码工作.groupby只返回组,而我需要一个值列表.
在pandas.fillna中,
method : {‘backfill’, ‘bfill’, ‘pad’, ‘ffill’, None}, default None
Method to use for filling holes in reindexed Series pad / ffill: propagate last valid observation forward to next valid backfill / bfill: use NEXT valid observation to fill gap
Run Code Online (Sandbox Code Playgroud)
如何向后和向前填充值?似乎没有一个选项可以做到这一点
我有2个数据框:
df_A
country_codes
0 4
1 8
2 12
3 16
4 24
Run Code Online (Sandbox Code Playgroud)
和df_B
continent_codes
0 4
1 3
2 5
3 6
4 5
Run Code Online (Sandbox Code Playgroud)
两个数据帧具有相同的长度,但没有公共列。我想将两者串联起来,但是由于并非所有值都是通用的,因此我得到了很多NaN。如何将它们串联或压缩到组合的数据框中?
-编辑所需的输出是这样的:
country_codes continent_codes
0 4 4
1 8 3
2 12 5
3 16 6
4 24 5
Run Code Online (Sandbox Code Playgroud) 我有一个愚蠢的。熊猫列表:
str = jan_1 jan_15 feb_1 feb_15 mar_1 mar_15 apr_1 apr_15 may_1 may_15 jun_1 jun_15 jul_1 jul_15 aug_1 aug_15 sep_1 sep_15 oct_1 oct_15 nov_1 nov_15 dec_1 dec_15
Run Code Online (Sandbox Code Playgroud)
有没有办法将其转换为日期时间?
我试过:
pd.to_datetime(pd.Series(str))
我有以下数组:
[1,1,1,1,1,1,nan,nan,nan,1,1,1,2,2,2,3,3]
Run Code Online (Sandbox Code Playgroud)
我想提取1此数组在nan之后的第一次出现。我尝试了这个:
numpy.argmax(arr > numpy.nan)
Run Code Online (Sandbox Code Playgroud) # Load dataset
iris = datasets.load_iris()
X, y = iris.data, iris.target
rf_feature_imp = RandomForestClassifier(100)
feat_selection = SelectFromModel(rf_feature_imp, threshold=0.5)
clf = RandomForestClassifier(5000)
model = Pipeline([
('fs', feat_selection),
('clf', clf),
])
params = {
'fs__threshold': [0.5, 0.3, 0.7],
'fs__estimator__max_features': ['auto', 'sqrt', 'log2'],
'clf__max_features': ['auto', 'sqrt', 'log2'],
}
gs = GridSearchCV(model, params, ...)
gs.fit(X,y)
Run Code Online (Sandbox Code Playgroud)
上述代码基于确保scikit learn中随机森林分类中的操作顺序
由于我使用的是SelectFromModel,我想打印所选功能的名称(在SelectFromModel管道中),但不确定如何提取它们.