- 博客(22)
- 收藏
- 关注
原创 pd.concat axis=1出现valueError报错,行数一样合并列
原因:index不同。用df.index发现,两个dataframe一个是RangeIndex, 另一个是int64。 解决方法:# 1. 将int64的index重新设置成rangeindexdf1.reset_index(inplace=True)df1.index# 2. ignore indexdf = pd.concat([df1, df2],ignore_index=True)print(df.index)...
2021-09-15 11:53:59
573
原创 奖牌RANK (python pandas)
使用dataframe的 sort_values 多列排序,全设置降序排列import pandas as pdmedal = { "金": [8, 8, 7, 10], "银": [3, 7, 5, 7], "铜": [8, 3, 7, 3], "总数": [19, 18, 19, 20],}df = pd.DataFrame(medal)rank = df.sort_values(by=["金", "银", "铜", "总数"], ascending=.
2021-07-27 14:32:22
618
原创 Pycharm 添加内容根 解决导包问题
问题:使用sys.path.append()添加路径后还是无法导包进入preferences 点击项目projects的项目结构,右边添加内容根 添加包目录 ✅
2021-03-24 16:30:57
518
原创 pytz 将date确定时区后转换成任意时区
目录0. goal1. pytz2. func3. 实例0. goal将字符串类型的日期时间, 如 "2021-03-1616:05:05" 确认为某一时区时间后,转换成北京时间。(根据个人需求去掉了时间只保留日期)1. pytz可以显示所有国家地区的各个时区,通过这个确定需要的时区pytz.all_timezonesOut[5]: ['Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', ...
2021-03-16 17:29:08
199
转载 Python发送邮件及各种附件
import smtplibfrom email.header import Headerfrom email.mime.application import MIMEApplicationfrom email.mime.multipart import MIMEMultipartfrom email.mime.text import MIMETextclass SendEmail: def __init__(self): """ 配置发件人信息 .
2021-03-03 18:50:52
161
1
转载 解压zip
importzipfilefile = "文件路径"zip_file = zipfile.ZipFile(file) # 读取zip文件zipfile.is_zipfile(zip_file) # 判断是否为zipprint(zip_file.namelist()) # 获取zip文档内所有文件的名称列表zip_file.extractall('输出的路径') # 解压全部文件...
2021-03-03 14:02:59
80
原创 pip->pip3, python2.7->python3.9
1. 由↓引出的问题pip3 install -r requirements.txt2.尝试更新pip解决python -m pip>>> 版本为2.7pip install --upgrade pip>>>Traceback (most recent call last): File "/usr/local/bin/pip", line 5, in <module> from pip._internal...
2021-03-02 23:32:05
175
转载 pandas读入excel 数字以00之类的开头
解决方法,直接在读入时变成strpd.read_excel("....", converters={u"以000之类开头的列名" : str})
2021-01-08 17:55:35
717
原创 error_bad_lines=False
# 跳过超出header字段的行,如4个字段,579行出现了 5个pd.read_table(, error_bad_lines=False)# 显示的跳过信息b'Skipping line 579: expected 4 fields, saw 5\n'
2020-12-25 16:00:44
4678
翻译 Role of Underscore (_)
1. interpreter里使用 as a particular variable>>> 5 + 49>>> _ # stores the result of the above expression9>>> _ + 615>>> _15>>> a = _ # assigning the value of _ to another variable>>> a15
2020-12-17 18:16:16
82
转载 替换多个字符
import unicodedatas = 'aac1233xyz'[in]t2 = s.translate({ord('a'): 'X', ord('3'): 'Y'}) print(t2)[out] XXc12YYxyz[in]t3 = s.translate({ord('a'): None, ord('3'): None}) print(t3)[out]c12xyz
2020-12-17 11:15:52
133
翻译 get column index
1.创建个dfdf = DataFrame({"pear": [1,2,3], "apple": [2,3,4], "orange": [3,4,5]})2.获取列名df.columns3.获取列的indexdf.columns.get_loc("pear")
2020-12-16 15:27:17
391
转载 **args **kw
参考https://www.jianshu.com/p/0ed914608a2c脚本:https://github.com/WENHUIn/python3.7/blob/main/*arg%26**kw.py
2020-12-16 00:19:41
55
翻译 TypeError: xxx takes 1 positional argument but 9 were given 【multiprocess】
args=(i)不是tupleargs=(i,)通过添加逗号,形成tupleAdd a comma; tuples are formed by the comma, not the parentheses (although you need parentheses to disambiguate the tuple from other arguments in a call)
2020-12-11 11:43:36
1570
转载 时间戳转时间 & 时间转时间戳
1. 时间戳转时间 【毫秒转】import datetimedef transfer_to_localtime(unix): localtime = datetime.datetime.fromtimestamp(unix / 1000) return localtimeEg:unix = 1605280519000date = transfer_to_localtime(unix)print(date)2020-11-13 23:15:192. 时间转时..
2020-12-03 15:09:06
431
翻译 Django 【Model】【坑】
1. 问题:TypeError: __init__() missing 1 required positional argument: 'on_delete'classForeignKey(to,on_delete,**options)[source]¶A many-to-one relationship. Requires two positional arguments: the class to which the model is related and theon_deleteo...
2020-12-02 11:45:12
169
转载 Django 链接MySQL 【坑】
1. -bash: mysql: command not foundhttps://www.jianshu.com/p/ba22165965692.django.db.utils.OperationalError: (1049, "Unknown database 'mydatabase'") 报错mysql> create database mydatabase character set uft8;https://blog.csdn.net/lo_bamboo/articl..
2020-11-27 17:50:32
156
翻译 PYTHONPATH for import
1.在终端里使用export PYTHONPATH="文件夹路径"2. 检查是否设置完成路径echo $PYTHONPATH
2020-11-27 10:23:38
243
原创 transfer脚本 【如何跳过异常值继续执行】【删除unnamed列】【字典遍历】
1.目标:将一串json格式字符串分列 该字符串位于dataframe的data列{"score": 527, "features": {"GD_M_103": 9.0, "GD_M_246": 70.0, "GD_M_238": 0.0, "GD_M_315": 11.0, "GD_M_107": 4.0, "GD_M_319": 6.0, "GD_M_2": 19.0, "GD_M_72": 1.0, "GD_M_60": 0.0, "GD_M_82": 1.0, "GD_M_6": 2.0.
2020-11-26 18:07:50
126
转载 convert string to dict
1. 使用 literal_evalfrom ast import literal_evalpython_dict = literal_eval("{'a': 1}")2. 使用 json.loads() 【注意,字符串必须为double quotes】import jsonpython_dict = json.loads('{"a": 1}')
2020-11-26 17:38:16
76
转载 dataframe尽量显示行和列
1. 容易卡死#显示所有列pd.set_option('display.max_columns', None)#显示所有行pd.set_option('display.max_rows', None)#设置value的显示长度为100,默认为50pd.set_option('max_colwidth',100)2. 比较好的写法# 设置显示行pd.options.display.max_rows = 300# 设置显示列pd.options.display.max_c.
2020-11-26 17:33:14
591
转载 字典get用法
Python 字典(Dictionary) get()方法https://www.runoob.com/python/att-dictionary-get.html语法get()方法语法:dict.get(key, default=None)参数key -- 字典中要查找的键。 default -- 如果指定键的值不存在时,返回该默认值。返回值返回指定键的值,如果键不在字典中返回默认值 None 或者设置的默认值。dict={'Name':'Runoob'...
2020-11-17 10:20:39
370
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人