第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Pandas dataframeplot():顯示x軸日期標(biāo)簽但不顯示數(shù)據(jù)

Pandas dataframeplot():顯示x軸日期標(biāo)簽但不顯示數(shù)據(jù)

翻過高山走不出你 2023-06-27 17:17:00
我正在嘗試將 pandas 數(shù)據(jù)框中的數(shù)據(jù)繪制為時(shí)間(年)的函數(shù)。數(shù)據(jù)摘要如下所示:           DATE    WALCL0    2010-08-18  23136621    2010-08-25  23010152    2010-09-01  23019963    2010-09-08  23058024    2010-09-15  2296079517  2020-07-15  6958604518  2020-07-22  6964755519  2020-07-29  6949032520  2020-08-05  6945237521  2020-08-12  6957277我嘗試使用以下代碼繪制數(shù)據(jù):import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport matplotlib.dates as mdatesyears = mdates.YearLocator()   # every yearmonths = mdates.MonthLocator()  # every monthyears_fmt = mdates.DateFormatter('%Y')dfData = pd.read_csv(sPathIn+sFname, skiprows = 0)ax = dfData.plot()ax.xaxis.set_major_locator(years)ax.xaxis.set_major_formatter(years_fmt)ax.xaxis.set_minor_locator(months)datemin = np.datetime64(dfData['DATE'][0], 'Y')datemax = np.datetime64(dfData['DATE'].iloc[-1], 'Y') + np.timedelta64(1, 'Y')ax.set_xlim( datemin, datemax)     plt.show()當(dāng)我運(yùn)行此代碼時(shí),繪圖軸顯示正確,但時(shí)間序列數(shù)據(jù) (WALCL) 未出現(xiàn)。如果我省略ax.set_xlim( datemin, datemax),則會(huì)顯示時(shí)間序列數(shù)據(jù),但 x 軸的格式不再正確(從 1970 年開始一直運(yùn)行到 1971 年)。這是修改后的代碼示例:import numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport matplotlib.dates as mdatesyears = mdates.YearLocator()   # every yearmonths = mdates.MonthLocator()  # every monthyears_fmt = mdates.DateFormatter('%Y')sPathIn = "C:\\Users\\reg\\projects\\notes\\Political_Economy\\S&P+Fed-Assets\\"sFname = "WALCL.csv"這是回溯:Traceback (most recent call last):  File "C:\Users\reg\projects\Notes\Political_Economy\S&P+Fed-Assets\Python\s&p-fed-assets-v0.2.3.py", line 25, in <module>    dfData.set_index('DATE', inplace=True)  File "C:\Users\reg\Anaconda3\lib\site-packages\pandas\core\frame.py", line 4545, in set_index    raise KeyError(f"None of {missing} are in the columns")KeyError: "None of ['DATE'] are in the columns"    # load data    dfData = pd.read_csv(sPathIn+sFname, skiprows = 0, parse_dates=['DATE'], index_col='DATE')        #set up plot fxn    dfData.set_index('DATE', inplace=True)    ax = dfData.plot('DATE', 'WALCL')   
查看完整描述

1 回答

?
叮當(dāng)貓咪

TA貢獻(xiàn)1776條經(jīng)驗(yàn) 獲得超12個(gè)贊

  • 數(shù)據(jù)集位于資產(chǎn):總資產(chǎn):總資產(chǎn)(減去合并沖銷):周三水平 (WALCL)

  • 使用with驗(yàn)證該DATE列是否采用日期時(shí)間格式。parse_dates.read_csv

設(shè)置DATE為索引

import pandas as pd

import numpy as np


# verify the DATE column is in a datetime format and set it as the index

dfData = pd.read_csv('WALCL.csv', skiprows=0, parse_dates=['DATE'], index_col='DATE')


# plot the data

ax = dfData.plot(figsize=(20, 8))


datemin = np.datetime64(dfData.index.min(), 'Y')

datemax = np.datetime64(dfData.index.max(), 'Y') + np.timedelta64(1, 'Y')

ax.set_xlim(datemin, datemax)

http://img3.sycdn.imooc.com/649aa95d0001cc8811420487.jpg

保留DATE為專欄

import pandas as pd


# read file

dfData = pd.read_csv('WALCL.csv', skiprows=0, parse_dates=['DATE'])


# plot data

ax = dfData.plot('DATE', 'WALCL', figsize=(20, 8))

http://img2.sycdn.imooc.com/649aa96b0001ba1111500486.jpg

查看完整回答
反對 回復(fù) 2023-06-27
  • 1 回答
  • 0 關(guān)注
  • 292 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)