在下面的图中,日期没有显示在x轴上,如何显示日期时间戳 import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import pandas_datareader as web
start=datetime.datetime(2014,1,8)
end =datetime.datetime(2019,1,8)
Tesla=web.DataReader('TSLA',"iex",start,end)
Ford=web.DataReader(
使用下面的代码,在转换回np.datetime64后,我得到了两个小时的差异。
我怎么才能避免这种情况?(如果这应该是一个话题:我现在在中欧)
import pandas as pd
import numpy as np
import datetime
a = np.datetime64('2018-04-01T15:30:00').astype("float")
a
b = np.datetime64(datetime.datetime.fromtimestamp(a))
b
Out[18]: numpy.datetime64('2018-04-0
我正在尝试将索引字符串更改为index,这是pandas dataframe中的datetime。
High Low Open Close Volume Adj Close
Date
1987-12-31 1.535714 1.495536 1.517857 1.500000 29400000.0 1.200883
1988-01-04 1.598214 1.508929 1.526786 1.598214 82600000.0 1.279513
1988-01-0
我在Pandas中创建了以下数据帧'user_char‘:
## Create a new workbook User Char with empty datetime columns to import data from the ledger
user_char = all_users[['createdAt', 'uuid','gasType','role']]
## filter on consumers in the user_char table
user_char = user_char[user_char
我无法使用xlsxwriter实现日期格式。我已经尝试过使用xlsxwriter在熊猫中使用数据格式的示例代码,但是添加了Sqldf步骤来过滤掉df,这略有不同。这里,我只使用sqldf步骤中的简单过滤器进行测试,但在实际场景中却很复杂。
有人能给我个建议吗,这里有什么问题吗。我已经检查了dtype,它在工作(实际示例)和非工作(sqldf步骤添加)情况下都是对象。
import pandas as pd
from datetime import datetime, date
from pandasql import sqldf
# Create a Pandas dataframe fro
我正在从一个DataFrame文件中读取hdf5:
import pandas as pd
store = pd.HDFStore('some_file.h5')
df= store['df']
store.close()
使用info显示:
In [11]: df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 21423657 entries, 0 to 21423656
Data columns (total 5 columns):
date datet
在Pandas数据帧中有2列: "CREATED ON DATE" (dtype: datetime64[ns]) e.g. 2019-06-16
"CREATED AT TIME" (dtype: object) e.g. 19:46:14 由于类型不匹配,简单地添加字段是不起作用的。 df["CREATED DATETIME"] = df["CREATED ON DATE"] + df["CREATED AT TIME"] 如何将这两列合并为1个日期时间字段"CREATED DATETIME"
我有这个df:
open high low close volume
date symbol
2014-02-20 AAPL 69.9986 70.5252 69.4746 69.7569 76529103
MSFT 33.5650 33.8331 33.4087 33.7259 27541038
2014-02-21 AAPL 69.9727 70.2061
我使用datetime.date字段作为我的索引,但由于某些原因,它似乎不同意它是datetime。
首先,我将验证字段是否确实是datetime.date格式:
In [1]: df[date][0]
Out [1]: datetime.date(2010, 1, 1)
现在我尝试按周重新采样,并绘制平均值:
In [2]: df.set_index(date)[var].resample('W', how='mean').plot()
/python2.7/site-packages/pandas/core/generic.pyc in resample