python 一些使用小语法

两个df的 columns相同,根据index进行连接合并:

result = pd.concat([df1,df2])

如何给dataframe的index换名字:
https://blog.csdn.net/RogerFedereYY/article/details/109121721

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')

找出SizeBC或者SCsize不为空的行

df[(~df['SizeBC'].isnull())|(~df['SCsize'].isnull())]

查看nan的

data[data.isnull().all(1)]

将两列时间拼接

sparse.png

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。