自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(25)
  • 收藏
  • 关注

原创 将multi-dimensional array转为one dimension

array.flatten()e.g.before:array1 = array1.flatten()after:

2021-05-10 16:30:33 135

原创 pandas qcut error:duplicate bins

fix unique bin error:duplicates='drop'decrease quantilesRank your data with DataFrame.rank(method=‘first’). The ranking assigns a unique value to each element in the dataframe (the rank) while keeping the order of the elements (except for identica

2021-04-27 10:37:08 730

原创 ValueError: Incompatible indexer with Series

ValueError: Incompatible indexer with Seriesreason: This problem occurs when a key in the dict refers to more than one value!e.g.:df = pd.DataFrame({"A": [1, 2, 3]})df# A#0 1#1 2#2 3num = np.mean(df)num#A 2.0#dtype: float64Then, when usi.

2021-04-22 17:27:48 10817

原创 pandas 获取已知特定index/日期的前n行、后n行数据

e.g. idx = '2020-03-20'n = 20# n rows beforedf.loc[:idx].tail(n)# n rows afterdf.loc[idx:].head(n)source: Get number of rows before and after a certain index value in pandas

2021-04-22 14:01:12 733

原创 np.sum 结果为nan, np.isnan出现TypeError

注意检查是否array中有nan值,如果有需要removeremove方法:array[~np.isnan(array)]如在使用np.isnan()是出现:TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''检查array

2021-04-14 10:11:58 937

原创 TypeError: ‘NoneType‘ object is not iterable

出现原因:None出现在了iterable的datatype中,比如出现在了set或者for循环e.g.[1,2].append([3,4]) #-- Noneset(None) #-- None

2021-04-14 10:07:05 340

原创 pandas日期加减一天

一个datetime类型的日期 cur_dt = '2021-03-01'想要得到前一天、后一天的日期:import datetimeprevious_date = cur_dt - datetime.timedelta(1)# output: Timestamp('2021-02-28 00:00:00')next_date = cur_dt + datetime.timedelta(1)# output: Timestamp('2021-03-02 00:00:00')...

2021-04-12 13:59:49 9469

原创 pandas两列相除为NaN

检查两列index是否一样,如不一样:df1 = df1.reset_index()df2 = df2.reset_index()df1['column1'] / df2['column1']如需例子可看:stackoverflow: Pandas divide creates extra columns and NaN

2021-04-08 16:33:10 1995

原创 pandas获取月底最后一个交易日对应数据

先尝试了:df.index是date,类型是datetimedf[df.index.day == df.index.days_in_month]和df[df.index == (df.index + pd.offsets.MonthEnd(0))]会只输出月底最后一天是交易日的数据如下方法成功:df.loc[df.groupby(df.index.to_period('M')).apply(lambda x: x.index.max())]两种方法来源:https://stackov

2021-04-08 14:40:56 7179 1

原创 str replace

若要更改原string,需重新赋值a = 'abc'print(a.replace('a', ''))# result: 'bc'print(a)# result: 'abc'a = a.replace('a', '')print(a)# result: 'bc'

2020-10-27 18:02:02 95

原创 conda activate失败

Your shell has not been properly configured to use ‘conda activate’提示方法:source activatesource deactivateorsource activateconda deactivate紧接着报错:‘source’ 不是内部或外部命令,也不是可运行的程序 或批处理文件。采用以下命令即可:activateconda deactivate之后 conda activate 可正常使用。.

2020-09-23 10:41:46 592

原创 Python 特征选择方法总结

【机器学习】特征选择(Feature Selection)方法汇总:过滤法:Pearson相关系数,Chi2验证,MIC,距离相关系数,方差选择法包装发:前向搜索,后向搜索,递归特征消除法嵌入法:加入惩罚项特征选择 (feature_selection)more:Embedded: L1-based feature selection, randomized sparse models, tree-based...

2020-08-07 10:26:36 552

原创 Python常用Library User Guide

sklearnpandasNumPyNumPy中文SciPystatsmodelsmatplotlib

2020-08-06 09:36:18 239

原创 Python list 根据list中的值查找索引

alist.index(x[, start[, end]])返回查找的值第一次出现的indexstart & end:alist.index('x',0,3)返回 ‘x’ 在slice内第一次出现的位置

2020-08-05 13:45:35 3412

原创 Python 判断list/dataframe是否为空

list1 = []#method 1if not len(list1): print('empty')else: print('not empty')#method 2if not list1: print('empty')else: print('not empty')

2020-08-04 14:06:43 740

原创 pandas重命名

列名重命名多种方法df.columns = list(range(5))df.rename(columns = {'original':'now'}, inplace = True)

2020-08-04 14:03:42 231 1

原创 Pandas series相关变换

在对dataframe中的一列做log变换时试图使用math.log(df['col1']),提示错误:TypeError: cannot convert the series to <class ‘float’>正确方法:df['col1'].apply(np.log)方法来源于:Pandas入门:对一列取指数/对数...

2020-07-30 10:34:00 378

原创 matplotlib绘图整理

Jupyter Notebook绘图(包含子图)图例;scatter

2020-07-30 10:26:04 109

原创 Python线性回归假设检验

https://blog.csdn.net/Noob_daniel/article/details/76087829

2020-07-30 09:38:04 879

原创 Pandas 列的位置和列名

根据列名获取列的位置:df.get_loc('name')根据列的位置获取列名df[df.columns[position]]

2020-07-24 16:28:50 1815

原创 pandas 数据查看与合并

total[col].value_counts()Result:total = pd.merge(df1, df2)

2020-07-22 14:35:50 154

原创 pandas列反转

```pythondate = date.reindex(index = date.index[::-1])date = date.reset_index(drop = True)date

2020-07-22 14:23:24 692

原创 matplotlib color &次坐标轴

color = 'colorname'fig, ax1 = plt.subplots() ax2 = ax1.twinx() ax1.plot(x,y) ax2.plot(x, y, color='darkorange')

2020-07-16 09:54:35 157

原创 Pandas索引不同方法区分

pandas索引``data = {‘Team’: [‘Riders’, ‘Riders’, ‘Devils’, ‘Devils’, ‘Kings’,‘kings’, ‘Kings’, ‘Kings’, ‘Riders’, ‘Royals’, ‘Royals’, ‘Riders’],‘Rank’: [1, 2, 2, 3, 3,4 ,1 ,1,2 , 4,1,2],‘Year’: [2014,2015,2014,2015,2014,2015,2016,2017,2016,2014,2015,20

2020-06-15 15:01:47 157

原创 Pandas计算结果为0.00013 输出后为0

注意之前设定的数据类型df['num'] = 0df['num'][i] = 0.1*0.3output = 0df['num'] = float(0)df['num'][i] = 0.1*0.3output = 0.03

2020-06-15 14:43:54 177

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除