我有一个Python熊猫数据框,在其中一个名为列status含有三种可能的值:ok,must read x more books,does not read any books yet,在x高于一个整数0.
我想status根据上面的顺序对值进行排序.
例:
name status
0 Paul ok
1 Jean must read 1 more books
2 Robert must read 2 more books
3 John does not read any book yet
Run Code Online (Sandbox Code Playgroud)
我发现了一些有趣的提示,使用Pandas Categorical和map但我不知道如何处理修改字符串的变量值.
我怎样才能做到这一点?
我试图了解如何使用 Python 3.9 类型提示来注释接收具有可选或多个类型值的字典的函数。我知道通过打字模块,我可以轻松使用Union和Optional. 但我想知道是否可以仅使用 Python 3.9 注释来实现这一点。我在PEP 585上没有找到任何关于此事的信息。
例子:
From Typing import Dict, Optional, Union
def foo(bar: Dict[Union[str, int], Optional[str]]) -> bool: return True
Run Code Online (Sandbox Code Playgroud)
我应该这样做吗:
from __future__ import annotations
def foo(bar: dict[[str, int], [str, None]) -> bool: return True
Run Code Online (Sandbox Code Playgroud) 我创建了一个 Rails api 来公开我的 Bottl 类。此类有一些解决99Bottles问题的方法。song例如,该方法返回完整的歌词歌曲。我的目的是根据包含该方法响应的JSON API返回一个 JSON。
require_relative '../bottles_logic/bottles'
class SongsController < ApplicationController
before_action :set_song, only: [:show, :update, :destroy]
# GET /songs
def index
@songs = ::Bottl.new.song
render json: @songs
end
end
Run Code Online (Sandbox Code Playgroud)
使用 Postman,我获得 200 状态和请求负载,但是,由于syntax error (unexpected 'S').
我的问题是:
我是灵丹妙药的新手。我想知道版本的组织方式以及如何知道哪个版本是最新的?我的机器中有 elixir 1.2 版,但我听说过 1.9 和 1.7 版,尽管它们似乎比 1.2 版早。