Python 常用数据处理

以下为积累 Python 常用数据处理方法,不定时更新。

1.遍历某文件夹下所有文件 :
files= os.listdir(path)

2.取消科学计数法:
np.set_printoptions(suppress=True), df[‘a’].astype(‘int64’)

3.判断 DataFrame 为空:
全部数据集 df.isnull()
为空的列 df.isnull().any()
挑选某一列为空的行 df[df[‘a’].isnull().values == True]
某一元素为空:np.isnan(x), x is np.nan

(一件有意思的事情是,np.nan == np.nan, np.nan is np.nan, np.isnan(np.nan) 的结果是不同的
http://lbingkuai.iteye.com/blog/1684971

4.str格式的时间转换成时间:
df[‘date’].apply(lambda x:datetime.datetime.strptime(x,’%Y-%m-%d’))

5.两个时间间隔天数:
(df[‘date1’] - df[‘date2’]).apply(lambda x:x.days)

6.list截取:
list[m:n],顾头不顾尾,末尾的值不被包含进来

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值