美文网首页
python 一些使用小语法

python 一些使用小语法

作者: Aerosols | 来源:发表于2020-04-03 16:57 被阅读0次

pandas只是提取指定时刻数据

###  挑选00:10,00:20...时刻的数据
tar_df=df.resample('10T',convention='start').asfreq()
### 挑选整点数据
tar_df=df.resample('H',convention='start').asfreq()

pandas 将某列小于1的数设为1:
方法1

df.loc[df['S']<1,'S']=1

方法2

df['S'] = np.where(df['S']<1, 1, df['S'])

方法3

df['S'] = df['S'].apply(lambda x: 1 if x<1 else x)

找出标签重复行:

sam[sam.index.duplicated()]
### Delete it.
sam_new = sam.loc[~sam.index.duplicated(keep='first')].copy()

删除重复行之一

DataFrame.drop_duplicates(subset=None, keep='first', inplace=False)

删除SizeBC为空的行

df[np.isfinite(df['SizeBC'])]     ## 将SizeBC 不为空的行取出来

df[pd.notnull(df['SizeBC'])]     ## 同样作用

及时清理内存

import gc    #####(garbage collector)
del a
gc.collect()

重新赋值时间index

t_index = pd.date_range('2019-12-07 17:30','2019-12-08 23:59:59.80' , freq='0.2S')
db=db.reindex(t_index)

只是筛选需要的时刻不做计算

aim_df=df.resample('0.5H',convention='start').asfreq()

改变数据类型为float32

BC[['SizeBC']]=BC[['SizeBC']].astype('float32')

将两列时间拼接

sparse.png
数学符号
https://matplotlib.org/tutorials/text/mathtext.html
图例位置:
legend

相关文章

网友评论

      本文标题:python 一些使用小语法

      本文链接:https://www.haomeiwen.com/subject/fzhdkhtx.html