所以我有一个pandas dataframe对象,其中包含两列小数位的精度,如"133.04".没有带有3个或更多小数位的数字,只有两个.
我已经尝试使用Decimal模块,但是当我尝试像这样重新采样时
gr_by_price = df['price'].resample(timeframe, how='ohlc')
Run Code Online (Sandbox Code Playgroud)
我明白了
pandas.core.groupby.DataError: No numeric types to aggregate
Run Code Online (Sandbox Code Playgroud)
在此之前我检查dtype
print(type(df['price'][0]))
<class 'decimal.Decimal'>
Run Code Online (Sandbox Code Playgroud)
我是这个图书馆和资金处理的新手,也许Decimal不是这个的正确选择?我该怎么办?
如果我将此列投射到<class 'numpy.float64'>一切正常.
更新:现在我正在使用这种方法
d.Decimal("%0.2f" % float(d.Decimal("1.04")))
Decimal('1.04')
Run Code Online (Sandbox Code Playgroud)
从这个问题
为什么这个切片示例不会给出与标准列表相同的结果?它的工作原理就像它首先评估an[:2] = bn[:2]然后bn[:2] = an[:2].
import numpy as np
l1 = [1, 2, 3]
l2 = [4, 5, 6]
a = list(l1)
b = list(l2)
an = np.array(a)
bn = np.array(b)
print(a, b)
a[:2], b[:2] = b[:2], a[:2]
print(a, b)
print(an, bn)
an[:2], bn[:2] = bn[:2], an[:2]
print(an, bn)
Run Code Online (Sandbox Code Playgroud)
输出:
--------------------
[1, 2, 3] [4, 5, 6]
[4, 5, 3] [1, 2, 6]
--------------------
[1 2 3] [4 5 6]
[4 5 3] [4 5 6] …Run Code Online (Sandbox Code Playgroud) 所以我通过这种方式获得了一个刷新令牌,我可以保留它吗?
如果是这样,我下次如何使用它,这样我就不需要打开浏览器了?
现在我正在考虑直接创建 OAuth2Credentials 对象,这是正确的方法吗?
from urllib.parse import urlparse, parse_qs
from oauth2client.client import flow_from_clientsecrets, OAuth2Credentials
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.contrib import gce
import httplib2
import webbrowser
CLIENT_SECRETS_FILE = "bot_credentials.json"
flow = client.flow_from_clientsecrets(
CLIENT_SECRETS_FILE,
scope=scope,
redirect_uri='http://127.0.0.1:65010')
flow.params['include_granted_scopes'] = 'true'
flow.params['access_type'] = 'offline'
auth_uri = flow.step1_get_authorize_url()
webbrowser.open(auth_uri)
url = input('Please enter the redirected url with code')
code = get_url_param(url, 'code')
if code is None:
print('there is an error …Run Code Online (Sandbox Code Playgroud) 我需要解析一个网页,它有很多图像,因此每个请求都需要花费很多时间。
我可以使用 requests.get 只获取 html 内容而不等待图像吗?
我正在尝试从表中检索不同日期的列表。它们以整数形式存储。
cal.getTime().getTime()
Run Code Online (Sandbox Code Playgroud)
返回自 1970 年 1 月 1 日格林威治标准时间 00:00:00 以来由此 Date 对象表示的毫秒数。
我写的
select strftime('%d-%m-%Y'," + date_clmn + ") from "
+ TABLE_NAME +" group by strftime('%d-%m-%Y'," + date_clmn + ")"
Run Code Online (Sandbox Code Playgroud)
接下来,我将这些值转换为字符串。我得到的:
24-11--471
Run Code Online (Sandbox Code Playgroud)
之后,当我尝试进行查询时
strftime('%d-%m-%Y',date_clmn)=24-11--471
Run Code Online (Sandbox Code Playgroud)
我什么也得不到。
怎么了?
使用这种方式我会遇到时区问题吗?
如果有其他方法可以做到,我会很高兴听到你的消息。
提前致谢。
更新
Tried "date(" + date_clmn+ ",'unixepoch')"
now retrieved value is "1970-01-01"
Run Code Online (Sandbox Code Playgroud) python ×3
python-3.x ×3
android ×1
date ×1
java ×1
numpy ×1
pandas ×1
sqlite ×1
youtube-api ×1