随笔分类 -  Python

[FAQ] Python的虚拟环境和包管理
摘要:1. 创建虚拟环境 $ python -m venv test-env 2. 激活虚拟环境 windows:tutorial-env\Scripts\activate (powershell: .\test-env\Scripts\Activate.ps1) linux:source tutoria 阅读全文

posted @ 2023-10-17 22:59 ercom 阅读(47) 评论(0) 推荐(0)

[Py] Python 的 shape、reshape 含义与用法
摘要:shape 方法用于查看数据是几行几列的。 reshape 方法用于不更改数据的情况下,重新把数据进行规划成指定的行数和列数。 .reshape(-1, 1) -1 表示自动,1 表示整理成 1 列数据。 .reshape(2, -1) 整理成 2 行的数据。 .reshape(3, 3) 整理成 阅读全文

posted @ 2020-07-20 16:32 ercom 阅读(1109) 评论(0) 推荐(0)

[Py] Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work
摘要:当通过常规命令安装 pip install pydot 和 brew install graphviz 之后,在代码中 import pydot 依旧不生效。 比如:在 tensorflow 使用 tf.keras.utils.plot_model 的时候,就会提示 Failed to import 阅读全文

posted @ 2020-07-03 14:34 ercom 阅读(806) 评论(0) 推荐(0)

[Py] Python dict 倒序操作
摘要:倒序操作很简单,使用 reversed( ) 方法,原本是 ['a', 'b', 'c'],倒序后就是 ['c', 'b', 'a'] Ref:在线运行Python代码 Refer:Python dict技巧 Link:https://www.cnblogs.com/farwish/p/132206 阅读全文

posted @ 2020-07-01 18:11 ercom 阅读(1347) 评论(0) 推荐(0)

[Py] Python 接口数据用 pandas 高效写入 csv
摘要:通过 pandas 把 dict 数据封装,调用接口方法写入 csv 文件。 import pandas as pd data = [{"name": "a"}, {"name": "b"}] pd_data = pd.DataFrame.from_dict(data) pd_data.to_csv 阅读全文

posted @ 2020-07-01 15:45 ercom 阅读(950) 评论(0) 推荐(0)

[Py] Python json str 字符串转为对象 (字典)
摘要:import json json = '{"code": 0}' # Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance containing a JSON document) to a Python object. o 阅读全文

posted @ 2020-07-01 14:36 ercom 阅读(2964) 评论(0) 推荐(0)

[Py] Python 字符串 str 和 字节 bytes 的互转
摘要:字节转字符串: st = str(data, encoding = "utf8") print(st) print(type(str)) # <class 'str'> 字符串转字节: by = bytes(st, encoding = "utf8") print(by) print(type(by 阅读全文

posted @ 2020-07-01 14:21 ercom 阅读(1194) 评论(0) 推荐(0)

[Py] Jupyter 写入和执行 python 文件
摘要:以 %%writefile request.py 开头。 下面写 python 代码,然后 shift + enter 键,可以把 python 代码写入开头指定的文件中,没有则自动创建。 以 %run request.py 的形式运行当前目录下的 python 文件。 也可以指定绝对路径。 To: 阅读全文

posted @ 2020-07-01 13:51 ercom 阅读(1563) 评论(0) 推荐(0)

[FAQ] Python list 的值是带有小括号的是什么意思 ?
摘要:python 中的 list 即列表,是用中括号 [ ] 表示的数组列表; dict 即字典,是用花括号 { } 表示的 json 对象; tuple 即元祖,是用小括号表示的序列; 见到它们之间的组合并不奇怪,比如 [ ('100230343': 100), ('1003234244': 200) 阅读全文

posted @ 2020-05-10 19:55 ercom 阅读(2186) 评论(1) 推荐(1)

[Py] 简单的 Python 运行环境
摘要:python:https://www.python.org/downloads/ pip:https://pip.pypa.io/en/stable/installing/#upgrading-pip pip is already installed if you are using Python 阅读全文

posted @ 2019-10-19 16:30 ercom 阅读(839) 评论(0) 推荐(0)