English 中文(简体)
每天返回不同时限
原标题:returning different time frames from datetime

我这样说:

for d in csvReader:
    print datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f").date()

日期: 2000-01-08,正确

页: 1

我将如何回馈信息,如日+时间”日+小时+分钟

http://www.ohchr.org。

我本来应该更确切地说,这就是我试图做到的:

lmb = lambda d: datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f").date()

daily_quotes = {}
for k, g in itertools.groupby(csvReader, key = lmb):
    lowBids = []
    highBids = []
    openBids = []
    closeBids = []
    for i in g:

        lowBids.append(float(i["Low Bid"]))
        highBids.append(float(i["High Bid"]))
        openBids.append(float(i["Open Bid"]))
        closeBids.append(float(i["Close Bid"]))

    dayMin = min(lowBids)
    dayMax = max(highBids)
    open = openBids[0]
    close = closeBids[-1]

    daily_quotes[k.strftime("%Y-%m-%d")] = [dayMin,dayMax,open,close]

如你所知,现在按日计为一米的数值,我想按小时(我需要时间+小时)或分钟(日期+小时+分钟)分类。

页: 1

最佳回答

Don t use the date/code> methods of datetime 页: 1 相反,将<条码>strftime直接用于从<条码>>>>上返回,使您能够进入包括年、月、日、小时、分钟、秒等在内的所有成员领域。

d = {"Date": "01-Jan-2000", "Time": "01:02:03.456"}
dt = datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f")
print dt.strftime("%Y-%m-%d-%H-%M-%S")
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签