我一直在处理一个小文件,我一直在编译和运行它。我的目录包含Log.hs和LogAnalysis.hs.
LogAnalysis.hs 看起来像这样:
{-# OPTIONS_GHC -Wall #-}
module LogAnalysis where
import Log
parseMessage :: String -> LogMessage
--some code...
main :: IO ()
main = do
putStrLn (show (parseMessage ("Some log message text")))
Run Code Online (Sandbox Code Playgroud)
当我LogAnalysis.hs用 GHC编译时,我得到了一个可执行文件,以及其他一些二进制文件:
$ ll
Log.hi
Log.hs
Log.o
LogAnalysis <-- this is the executable which has disappeared
LogAnalysis.hi
LogAnalysis.hs
LogAnalysis.o
Run Code Online (Sandbox Code Playgroud)
我做了一些小改动,现在当我运行时,ghc LogAnalysis.hs我只得到.hi和.o文件,但没有可执行文件。输出是:
[1 of 2] Compiling Log ( Log.hs, Log.o )
[2 of 2] Compiling LogAnalysis …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,它似乎是多索引的一个简单用例:我有 ISO 周数和日期作为索引,我想按特定周进行过滤。按照docs 中的说明 ,看起来我应该能够通过传递一串周数来建立索引。但是,这给了我一个关键错误。
MCVE:
data = {'foo': {('2016_32', '2016-08-07'): 0.14285714285714285,
('2016_32', '2016-08-08'): 0.14285714285714285,
('2016_32', '2016-08-09'): 0.14285714285714285,
('2016_32', '2016-08-10'): 0.14285714285714285,
('2016_32', '2016-08-11'): 0.14285714285714285,
('2016_32', '2016-08-12'): 0.14285714285714285,
('2016_32', '2016-08-13'): 0.14285714285714285,
('2016_36', '2016-09-04'): 0.14285714285714285,
('2016_36', '2016-09-05'): 0.14285714285714285,
('2016_36', '2016-09-06'): 0.14285714285714285,
('2016_36', '2016-09-07'): 0.14285714285714285,
('2016_36', '2016-09-08'): 0.14285714285714285,
('2016_36', '2016-09-09'): 0.14285714285714285},
'bar': {('2016_32', '2016-08-07'): np.nan,
('2016_32', '2016-08-08'): np.nan,
('2016_32', '2016-08-09'): np.nan,
('2016_32', '2016-08-10'): np.nan,
('2016_32', '2016-08-11'): np.nan,
('2016_32', '2016-08-12'): np.nan,
('2016_32', '2016-08-13'): np.nan,
('2016_36', '2016-09-04'): 0.0,
('2016_36', '2016-09-05'): 0.0,
('2016_36', '2016-09-06'): …Run Code Online (Sandbox Code Playgroud) 我继承了看起来像这样的代码。
class Clients(IntEnum):
ALICE = 1
BOB = 2
PETER = 3
CHERYL = 4
LARRY = 5
Run Code Online (Sandbox Code Playgroud)
if client_id == 1:
client_info = find_info(Clients.ALICE.value)
elif client_id == 2:
client_info = find_info(Clients.BOB.value)
elif client_id == 3:
client_info = find_info(Clients.PETER.value)
elif client_id == 4:
client_info = find_info(Clients.CHERYL.value)
elif client_id == 5:
client_info = find_info(Clients.LARRY.value)
else:
raise Exception('Unknown client_id.')
Run Code Online (Sandbox Code Playgroud)
对 Python 枚举没有太多经验,我强烈希望将其简化为这样的(伪代码):
if client_id in dict(Clients).keys():
client_info = find_info(client_id)
else:
raise Exception('Unknown client_id.')
Run Code Online (Sandbox Code Playgroud)
我试过Clients.__members__and Clients.__dict__,但它们的行为并不像我期望的那样,返回了一个叫做 a 的东西mappingproxy。 …
我正在使用命令 df.corr() 计算 Python Spyder 中数据集的相关矩阵。但是,输出仅显示前两列和最后两列的矩阵值。我应该使用什么命令才能获得整个矩阵?
我正在使用 pandas 包来计算给定数据集的相关矩阵。
我用于计算相关矩阵的代码是:
correlation_matrix = df.corr()
print(correlation_matrix)
Run Code Online (Sandbox Code Playgroud)
其结果是显示前两列和最后两列的相关矩阵值。我想要显示整个矩阵。
我有一个数据框,其中有一列时间戳类型。我想找到自午夜以来经过的时间(以秒为单位)作为新列。如何以简单的方式做到这一点?
例如:输入:
samples['time']
2018-10-01 00:00:01.000000000
2018-10-01 00:00:12.000000000
Run Code Online (Sandbox Code Playgroud)
type(samples['time'].iloc[0])
<class 'pandas._libs.tslib.Timestamp'>
Run Code Online (Sandbox Code Playgroud)
输出 :
samples['time_elapsed']
1
12
Run Code Online (Sandbox Code Playgroud) 我正在添加一个transform带有以下代码的列:
df['new_date'] = df.groupby('account')['date'].transform('last')
Run Code Online (Sandbox Code Playgroud)
这工作正常,但是默认情况下它会丢弃NaNs(如此处、此处和此处的现有错误中所述),我想保留它。开发人员建议nth(-1)改用。没问题!
但是,我不知道如何将它与transform. 错误信息为
`df.groupby('a')['b'].transform('nth')`
Run Code Online (Sandbox Code Playgroud)
is nth() missing 1 required positional argument: 'n',这似乎很诱人地暗示转换可以识别该方法,只要我能找到一种将索引传递给它的方法。但没有一个
df.groupby('a')['b'].transform('nth(-1)')
df.groupby('a')['b'].transform('nth'(-1))
df.groupby('a')['b'].transform('nth')(-1)
Run Code Online (Sandbox Code Playgroud)
工作。有没有办法做到这一点?
我需要一个函数来加倍列表中的每个其他数字.这样做的诀窍:
doubleEveryOther :: [Integer] -> [Integer]
doubleEveryOther [] = []
doubleEveryOther (x:[]) = [x]
doubleEveryOther (x:(y:zs)) = x : 2 * y : doubleEveryOther zs
Run Code Online (Sandbox Code Playgroud)
然而,问题是我需要从右边开始加倍每个其他数字- 所以如果列表的长度是偶数,那么第一个将加倍,等等.
我理解在Haskell中向后操作列表很棘手,所以我的计划是反转列表,应用我的函数,然后再次输出反向.我有一个reverseList功能:
reverseList :: [Integer] -> [Integer]
reverseList [] = []
reverseList xs = last xs : reverseList (init xs)
Run Code Online (Sandbox Code Playgroud)
但是我不太确定如何将它植入我原来的功能中.我得到这样的事情:
doubleEveryOther :: [Integer] -> [Integer]
doubleEveryOther [] = []
doubleEveryOther (x:[]) = [x]
doubleEveryOther (x:(y:zs)) =
| rev_list = reverseList (x:(y:zs))
| rev_list = [2 * x, y] ++ …Run Code Online (Sandbox Code Playgroud) 我正在尝试fillna使用合适的变量为每列添加一个。我的目标是尝试在最高级别的通用性上找到列类型:基本上,目前它是 numeric (int/float)、string 或 pandas Timestamp。我知道我可以检测数值或使用字符串numpy.issubdtype和类型层次,但我还没有找到一种方法来检测Timestamp。我的解决方案使用iloc[0]and isinstance,但还有更好的方法吗?这是我的代码,大致如下:
for col in df:
if np.issubdtype(dataframe[col].dtype, np.number):
df[col] = df[col].fillna(-1)
elif isinstance(dataframe[col].iloc[0], pd.datetime):
df[col] = df[col].fillna(pd.to_datetime('1900-01-01'))
else:
df[col] = df[col].fillna('NaN')
return (dataframe.fillna(na_var)
Run Code Online (Sandbox Code Playgroud)
(请注意,我不能使用,df.loc[0, col]因为我的索引并不总是包含 0。)
应用程序结构(Python FastAPI):
-my_app
-server.py
-Procfile
-requirements.txt
Run Code Online (Sandbox Code Playgroud)
为了安装 Heroku 应用程序所需的私有 git 存储库,我将以下行添加到我的requirements.txt:
git+https://<github-token>@github.com/me/my-private-repo.git
Run Code Online (Sandbox Code Playgroud)
然而,在推送时,Github 给我发了一封电子邮件,说由于我在提交中暴露了我的令牌,所以它已撤销了该令牌。(我的应用程序存储库是私有的。)完全公平!但是,我的 Heroku 构建现在失败了,因为它在尝试安装私有存储库时提示输入密码。
我在互联网上搜索过很多次 re: private repos,但总是遇到相互矛盾的建议。
我们将很高兴听到在这种情况下,在自动化构建中安全安装私有存储库的最佳实践是什么。
到目前为止我尝试过的:
git+git://username:password@github.com/me/myrepo.git而不是令牌显然有同样的问题git+ssh://git@github.com/me/myrepo.git- 产生错误Host key verification failed.pip要扩展该ssh选项,请在我的本地计算机上执行以下操作:
pip3 install git+ssh://git@github.com/me/my_private-repo.gitgit clone https://github.com/me/my_private-repo.git然而,当我的requirements.txtcontains时git+ssh://git@github.com/me/my_private-repo.git,我的 Heroku 构建会返回Host key verification failed. fatal: Could not read from remote repository. Please make sure you have the correct access rights and …
我刚刚开始学习Haskell,并且正在尝试编写一个计算列表中元素数量的程序.我在网上找到了这个代码:
listnumber :: [Int] -> Int
listnumber [] = 0
listnumber (x:xs) =1 + listnumber xs
Run Code Online (Sandbox Code Playgroud)
在GHCi中加载后,程序按预期返回列表的长度.但是这段代码如何直观地工作?