statsmodels.api cannot import 'factorial'
pip uninstall scipy -y
pip install scipy==1.2.0
auto_arima
pip install pyramid-arima
boxplot返回值
d = plt.boxplot(array, vert=False, showmeans=True)
d['caps'][idx].get_xdata() # idx:1最大值,0最小值. 为坐标点
数据叠加表
plt.style.use('seaborn-white')
type_cluster = stores.groupby(['type','cluster']).size()
type_cluster.unstack().plot(kind='bar',stacked=True, colormap= 'viridis', figsize=(12,8), grid=False)
pandas 循环
srt_set = set()
for row in pad.itertuples():
srt_set.update(row.colname.split())
'utf-8' codec can't decode byte 0xe9 in position 2892
import codecs
codecs.open("file",'r',encoding = "ISO-8859-1")
python 自定义排序
a = [(3,1),(1,1),(2,3),]
# lambda方法
a.sort(key=lambda x:(x[1],x[0]))
# 自定义函数
import functools
def reversed_cmp(x, y):
if x[1] < y[1]:
return -1
elif x[1] > y[1]:
return 1
elif x[0] < y[0]:
return -1
elif x[0] > y[0]:
return 1
return 0
a.sort(key=functools.cmp_to_key(reversed_cmp))
database is locked
con = sql.connect(dbname, timeout=10)
python 形参与实参
- 参数以列表传入,其中操作有
+=extend,append,pop
则为实参,即使重新赋值后path = path[i:j]
,嵌套后为形参,嵌套前仍为实参,这时混乱开始。
- 列表中元素为列表,子列表为实参,则当子列表的变量改变时,列表元素也随之改变,如
path=[], ans.append(path)
,当path
改变,ans
也随之改变,故ans.append(path[:])
.
时间节约
- 创建
tuple
比list
时间短
python count distinct
data.groupby('userid').shopid.nunique()