pandas
Tyanw
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 941 阅读 · 0 评论 -
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 · 11281 阅读 · 0 评论 -
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 · 979 阅读 · 0 评论 -
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 · 10121 阅读 · 0 评论 -
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 · 2228 阅读 · 0 评论 -
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 · 7644 阅读 · 1 评论 -
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 · 859 阅读 · 0 评论 -
pandas重命名
列名重命名多种方法df.columns = list(range(5))df.rename(columns = {'original':'now'}, inplace = True)原创 2020-08-04 14:03:42 · 329 阅读 · 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 · 475 阅读 · 0 评论 -
Pandas 列的位置和列名
根据列名获取列的位置:df.get_loc('name')根据列的位置获取列名df[df.columns[position]]原创 2020-07-24 16:28:50 · 1979 阅读 · 0 评论 -
pandas 数据查看与合并
total[col].value_counts()Result:total = pd.merge(df1, df2)原创 2020-07-22 14:35:50 · 227 阅读 · 0 评论 -
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 · 215 阅读 · 0 评论 -
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 · 254 阅读 · 0 评论
分享