V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  cassidyhere  ›  全部回复第 2 页 / 共 3 页
回复总数  55
1  2  3  
2021-04-01 10:39:30 +08:00
回复了 SelectLanguage 创建的主题 Java 一个非常复杂的需求,如何设计表结构
能用 nosql 吗
2021-03-11 12:33:55 +08:00
回复了 yaleyu 创建的主题 Python 又来求教 pandas 大拿了
如果 A/B 没规律的话,可以用自定义 window rolling
from pandas.api.indexers import BaseIndexer
window_size = df.C.groupby((df.C != df.C.shift(1)).cumsum()).agg('sum').max() # 最大连续次数
class CustomIndexer(BaseIndexer):
def get_window_bounds(self, num_values, min_periods, center, closed):
start = np.empty(num_values, dtype=np.int64)
end = np.empty(num_values, dtype=np.int64)
for i in range(num_values):
end[i] = i + 1
j = i
while j > 0 and self.use_expanding[j]:
j -= 1
start[i] = j
return start, end
indexer = CustomIndexer(window_size=window_size, use_expanding=df.C)
res = df.B.rolling(indexer, min_periods=2).sum().fillna(0)
2021-03-05 10:35:32 +08:00
回复了 zhoudaiyu 创建的主题 Python 学了 1 年 Python ,今天看了段代码觉得白学了,求教一下大家
标准库 functools.lru_cache 把它当双向链表用
摘部分代码:
PREV, NEXT, KEY, RESULT = 0, 1, 2, 3 # names for the link fields
root = [] # root of the circular doubly linked list
root[:] = [root, root, None, None] # initialize by pointing to self

# Use the old root to store the new key and result.
oldroot = root
oldroot[KEY] = key
oldroot[RESULT] = result
# Empty the oldest link and make it the new root.
# Keep a reference to the old key and old result to
# prevent their ref counts from going to zero during the
# update. That will prevent potentially arbitrary object
# clean-up code (i.e. __del__) from running while we're
# still adjusting the links.
root = oldroot[NEXT]
oldkey = root[KEY]
oldresult = root[RESULT]
root[KEY] = root[RESULT] = None
2021-02-07 23:29:14 +08:00
回复了 sdushn 创建的主题 Python 请教大佬们如何用 pandas 高效读取被分片的 csv 文件
各位想复杂了,pandas.read_csv 有现成的 chunksize 参数
2020-11-03 09:46:53 +08:00
回复了 ylsc633 创建的主题 汽车 马上 2021 年了, 国产车到底行不行
国产车比国产程序员质量好一点
2020-08-16 14:38:13 +08:00
回复了 huqay 创建的主题 Python 求教 pandas 输出到 Excel,=号如何以正常字符串输出并正确显示
pd.read_excel 有个可选参数 parse_cols
2020-08-16 14:35:13 +08:00
回复了 yangva 创建的主题 Python Python 的 pickle 或者 shelve 库为什么不能 dump 一个 gevent 协程对象
greenlet.getcurrent 。
你的需求和 flask 的实现好像,可以看看 werkzeug.local 的源码
2020-07-10 15:28:37 +08:00
回复了 7otk 创建的主题 职场话题 怎么样才能说服自己“单休也挺好的”
先体验无休~
2020-07-10 09:52:05 +08:00
回复了 maobukui 创建的主题 Python 请教 Python 中 xml 转 dict 格式--不懂就问
你可以用 collections.ChainMap,或者参考 flask 里的 MultiDict:
>>> d = MultiDict([('a', 'b'), ('a', 'c')])
>>> d
MultiDict([('a', 'b'), ('a', 'c')])
>>> d['a']
'b'
>>> d.getlist('a')
['b', 'c']
2020-07-02 18:39:35 +08:00
回复了 yellowtail 创建的主题 Python 如何优雅实现 dataframe 间隔行比较不同列的值
df['diff'] = df.high.shift() - df.high
df[df.diff > 0][df.markf == -1]
2020-07-01 09:53:42 +08:00
回复了 nanfangzai 创建的主题 Flask flask 如何验证 post 提交的 json 数据
Marshmallow/Pydantic/JSON Schema
2020-06-18 10:14:51 +08:00
回复了 xiaotianhu 创建的主题 程序员 此生,达成什么成就,才能让你不后悔?
财大气粗,德高望重
2020-05-26 10:36:26 +08:00
回复了 huazhaozhe 创建的主题 Python Python 如何实现一个和属性值相关的单例?
你需要创建缓存实例
python cookbook 里的例子:

import weakref

class Cached(type):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.__cache = weakref.WeakValueDictionary()

def __call__(self, *args):
if args in self.__cache:
return self.__cache[args]
else:
obj = super().__call__(*args)
self.__cache[args] = obj
return obj

# Example
class Spam(metaclass=Cached):
def __init__(self, name):
self.name = name


>>> a = Spam('Guido')
>>> b = Spam('Diana')
>>> c = Spam('Guido') # Cached
>>> a is b
False
>>> a is c # Cached value returned
True
2020-04-18 19:49:15 +08:00
回复了 smallgoogle 创建的主题 Python 我怀疑这是 Python for 的一个 bug
用队列。。。
2020-04-10 13:10:33 +08:00
回复了 MainHanzo 创建的主题 Python parquet 格式转换法案
1.最新的 pyarrow 是支持 nested data 的: https://github.com/apache/arrow/pull/6751/files
2.这时 pandas dataframe 转 csv 没问题:
s = StringIO()
df = pd.DataFrame({'c1': [[1, 2]], 'c2': [{'k': 'v'}]})
df.to_csv(s, index=False)
s.seek(0)
s.read() # 'c1,c2\r\n"[1, 2]",{\'k\': \'v\'}\r\n'
楼主同事买房和他积蓄 15 万一点关系都没有,和他月薪 3w 公积金 6k 有关系。
标题不写成“月薪 3w 公积金 6k 积蓄在郊区买房的故事,买房真没那么难”,而是“15w 积蓄在郊区买房的故事,买房真没那么难”,这是偷换概念,挨骂一点不冤。
2020-02-10 10:16:29 +08:00
回复了 black11black 创建的主题 Python Python 有办法限制字典不能添加新键吗 ?
可以参考 werkzeug.datastructures 里实现的 ImmutableDict
flask 就用到了
class Flask(_PackageBoundObject):
...
default_config = ImmutableDict({"ENV": None, ...})
2019-12-27 09:58:10 +08:00
回复了 plko345 创建的主题 Python 求助, 这段代码怎么复用
def stats(callback_name, **tags):
for instance_id in get_category_instance_id_by_tags(**tags):
ecs_obj = ECSInstance(instance_id)
yield getattr(ecs_obj, callback_name)


def cal_category_ecs_cpu_core_amount_by_tags(**tags):
return sum(stats('get_cpu_core', **tags))


def cal_category_ecs_memory_amount_by_tags(**tags):
return sum(stats('get_memory', **tags))


其实应该修改的是 ECSInstance
2019-12-12 10:14:35 +08:00
回复了 JCZ2MkKb5S8ZX9pq 创建的主题 Python Python 快速计算增量的方法
涉及循环或序列里元素间的操作,可以看看 itertools, operator, functools
1  2  3  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1185 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 52ms · UTC 23:38 · PVG 07:38 · LAX 16:38 · JFK 19:38
Developed with CodeLauncher
♥ Do have faith in what you're doing.