数据清洗须知2

4 篇文章 0 订阅
4 篇文章 0 订阅
什么是Jupyter

1. Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言。
2. Jupyter Notebook 的本质是一个 Web 应用程序,便于创建和共享文学化程序文档,支持实时代码,数学方程,可视化和markdown。 用途包括:数据清理和转换,数值模拟,统计建模,机器学习等等 。https://baike.baidu.com/item/Jupyter
3. Jupyter notebook:集文本、代码、图像、公式的展现于一体的超级python web界面

### 四. Ipython

1. 启动:ipython notebook/jupyter notebook

2. Ipython帮助文档

   1. Help(参数)方法: help(len)

   2.  ? 

       ?? : 可以显示源码

      ```python
      chr?
      /
      L=[1,2,3]
      L?
      /
      def myFunc(i):
          """
          help test
          """
          return i
      myFunc(10)
      myFun??
      ```

   3. tab自动补全

      ```python
      # python代码可以使用tab自动补全
      import re
      r = re.split(r"\\","a\\b\\v")
      print(r)
      ```

3. Ipython魔法指令

   1. 运行外部Python文件:%run a.py(当前路径)
      运行其他路径:%run C:/Users/ijeff/Desktop/bb.py

      > 尤其要注意的是,当我们使用魔法命令执行了一个外部文件时
      > 该文件的函数就能在当前会话中使用

   2.  运行计时

      1. 用下面命令计算statement的运行时间:
         %time statement

         ```python
         def p():
             for i in range(100):
                 print(i)
         
         %time p()
         def add():
             i = 0
             t = 0
             while i <=100000000:
                 t += i
                 i += 1
                 if(i == 100000000):
                     print(t)
         %time add()
         ```

      2. 用下面命令计算statement的平均运行时间:
         %timeit statement

         ```python
         tup1 = ('physics', 'chemistry', 1997, 2000);
         %timeit print(tup1)
         ```

         > %time一般用于耗时长的代码段
         > %timeit一般用于耗时短的代码段

      3. 可以使用两个百分号来测试多行代码的平均运行时间:
         %%timeit
         statement1
         statement2
         statement3

         ```python
         %%timeit
         print(1)
         print(2)
         ```

   3. 查看当前会话中的所有变量与函数

      1. 快速查看当前会话的所有变量与函数名称:
         %who

         ```
         L	 a	 add	 b	 even	 i	 myFunc	 np	 num	 
         numpy	 nums	 odd	 p	 r	 re	 square	 t	 tup1
         ```

      2. 查看当前会话的所有变量与函数名称的详细信息:
         %whos

         ```
         Variable   Type        Data/Info
         --------------------------------
         L          list        n=3
         a          list        n=3
         add        function    <function add at 0x7f6e81345a60>
         ```
         
      3. 返回一个字符串列表,里面元素是当前会话的所有变量与函数名称:
         %who_ls
      
         ```
         ['L',
          'a',
          'add',
         ]
         ```
      
   4. 执行Linux指令使用!
   
      ```shell
      Linux指令:
   
      $ echo "hello world"             # echo is like Python's print function
      hello world
   
      $ ls                             # ls = list working directory contents
      notebooks  projects 
      
      $ mkdir mm						#创建新路径
      
      ##桌面上创建文件夹
      !mkdir ../../../../Desktop/earth
      
      # 在Linux指令之前加上感叹号,即可在ipython当中执行Linux指令。
      # 注意会将标准输出以字符串形式返回
      ```
      
   5. 更多魔法指令
   
      ```python
      # 列出所有魔法命令
      lsmagic
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值