TypeError:' value'在matplotlib中,str或字节的实例,而不是浮点
我无法弄清楚为什么在代码的第一行中遇到一个值类型错误。 我查看了TypeError问题的其他答案,但看不到错误。
我的模块
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib as mpl
import matplotlib.font_manager as font_manager
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'Lato'
import numpy as np
import pandas as pd
我的数据框看起来像这样 | | |计数|非无效| dtype | | --- | ------------ | ------- | ------------------------------------------------- - | | 0 |日期| 1305 |非无效| datetime64 [ns] | | 1 | effr | 1305 |非无效|对象| | 2 | Prontsyd | 1306 |非无效|对象| | 3 | rrpontsyd | 1306 |非无效|对象| | 4 | rptsyd | 1306 |非无效|对象| | 5 | rrptsyd | 1306 |非无效|对象|
该错误发生在以下代码的第一行上,
stirs = pd.read_csv(r'C:/Users/Owner/Documents/Research/SOMA/FRED_reserves/SOMArates2.csv',\
verbose =True , warn_bad_lines = True, \
usecols=[0,1,2,3,4,5], parse_dates=['DATE'] )
stirs.info()
stirs.columns = stirs.columns.str.strip()
stirs['DATE'] = pd.to_datetime(stirs['DATE'],format='%m/%d/%Y')
date = stirs.loc[:, "DATE"]
eff = stirs.loc[:, "EFFR"]
repo = stirs.loc[:, "RPONTSYD"]
rrepo = stirs.loc[:, "RRPONTSYD"]
mrepo = stirs.loc[:, "RPTSYD"]
mrrepo = stirs.loc[:, "RRPTSYD"]
print(eff)
print(mrrepo)
x=stirs['DATE']
plt.figure(figsize=(5, 2.7), layout='constrained')
plt.plot(x, eff, label='Effective Fed Funds') [**]
plt.plot(x, repo, label='Repos')
plt.plot(x, rrepo, label='Reverse repo')
plt.plot(x, mrepo, label='Repos_OMO')
plt.plot(x, mrrepo, label='Reverse Repos_OMO')
plt.xlabel('Date')
plt.ylabel('y label')
plt.title("Effective FF rate, repo, reverse repo")
plt.legend()
plt.savefig('C:/Users/Owner/Documents/Research/SOMA/Soma_stirs.eps')
计数 | 非零 | dtype | ||
---|---|---|---|---|
0日 | 期 | 1305 | non-null | dateTime64 [ns] |
1 | effr | 1305 | 非零 | 对象 |
2 | prontsyd | 1306 | 非零 | 对象 |
3 | rrpontsyd | 1306 | 非零 | 对象 |
4 | rptsyd | 1306 | rptsyd 1306 rptsyd 1306非null | 对象 |
5 | rrptsyd | 1306 | non-null | objectplt.show() |
我从上面的代码中获得此错误:
TypeError: 'value' must be an instance of str or bytes, not a float
I cannot figure out why I'm getting a value type error in the first line of my code.
I've looked at the other answers to TypeError problems, but cannot see the error.
My Modules
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib as mpl
import matplotlib.font_manager as font_manager
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = 'Lato'
import numpy as np
import pandas as pd
My Dataframe looks like this
| | | Count | Non-Null | Dtype |
|---|-----------|-------|----------|----------------|
| 0 | DATE | 1305 | non-null | datetime64[ns] |
| 1 | EFFR | 1305 | non-null | object |
| 2 | PRONTSYD | 1306 | non-null | object |
| 3 | RRPONTSYD | 1306 | non-null | object |
| 4 | RPTSYD | 1306 | non-null | object |
| 5 | RRPTSYD | 1306 | non-null | object |
The error occurs on the first line of the code below
stirs = pd.read_csv(r'C:/Users/Owner/Documents/Research/SOMA/FRED_reserves/SOMArates2.csv',\
verbose =True , warn_bad_lines = True, \
usecols=[0,1,2,3,4,5], parse_dates=['DATE'] )
stirs.info()
stirs.columns = stirs.columns.str.strip()
stirs['DATE'] = pd.to_datetime(stirs['DATE'],format='%m/%d/%Y')
date = stirs.loc[:, "DATE"]
eff = stirs.loc[:, "EFFR"]
repo = stirs.loc[:, "RPONTSYD"]
rrepo = stirs.loc[:, "RRPONTSYD"]
mrepo = stirs.loc[:, "RPTSYD"]
mrrepo = stirs.loc[:, "RRPTSYD"]
print(eff)
print(mrrepo)
x=stirs['DATE']
plt.figure(figsize=(5, 2.7), layout='constrained')
plt.plot(x, eff, label='Effective Fed Funds') [**]
plt.plot(x, repo, label='Repos')
plt.plot(x, rrepo, label='Reverse repo')
plt.plot(x, mrepo, label='Repos_OMO')
plt.plot(x, mrrepo, label='Reverse Repos_OMO')
plt.xlabel('Date')
plt.ylabel('y label')
plt.title("Effective FF rate, repo, reverse repo")
plt.legend()
plt.savefig('C:/Users/Owner/Documents/Research/SOMA/Soma_stirs.eps')
Count | Non-Null | Dtype | ||
---|---|---|---|---|
0 | DATE | 1305 | non-null | datetime64[ns] |
1 | EFFR | 1305 | non-null | object |
2 | PRONTSYD | 1306 | non-null | object |
3 | RRPONTSYD | 1306 | non-null | object |
4 | RPTSYD | 1306 | non-null | object |
5 | RRPTSYD | 1306 | non-null | objectplt.show() |
I get this error from the code above:
TypeError: 'value' must be an instance of str or bytes, not a float
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论