【问题标题】:TypeError while using pydbgen module使用 pydbgen 模块时出现类型错误
【发布时间】:2020-11-22 06:48:32
【问题描述】:

我正在尝试使用 pydbgen 模块中的一些功能。其中一些有效,而另一些则不断给我以下错误:

import pydbgen
from pydbgen import pydbgen
myDB=pydbgen.pydb()

testdf=myDB.gen_dataframe(5,['name','city','phone','date'])
Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/pythonProject1/BIrainSensor.py", line 5, in <module>
    testdf=myDB.gen_dataframe(5,['name','city','phone','date'])
  File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\pydbgen\pydbgen.py", line 330, in gen_dataframe
    df = pd.DataFrame(data=self.gen_data_series(num,data_type=fields[0]),columns=[fields[0]])
  File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\pydbgen\pydbgen.py", line 191, in gen_data_series
    fake.seed(self.seed)
  File "C:\Users\user\PycharmProjects\pythonProject1\venv\lib\site-packages\faker\proxy.py", line 83, in __getattribute__
    raise TypeError(msg)
TypeError: Calling `.seed()` on instances is deprecated. Use the class method `Faker.seed()` instead.

我尝试用谷歌搜索,但一无所获。 我也尝试将 Faker 降级到 2.0.0 版本,但它不起作用

更新:似乎代码在 CMD 提示符下运行良好,但在 Pycharm 中仍然无法运行

提前致谢

【问题讨论】:

  • gen_dataframe 可能只接收字符串参数。所以试着把 5 改成 '5'
  • @redmicelles 没用

标签: python faker


【解决方案1】:

安装 Faker 2.0.5 对我有用

pip install Faker==2.0.5

示例:

myDB = pydbgen.pydb()
testdf = myDB.gen_dataframe(5,['name','city','phone','date'])
print(testdf)

输出:

               name            city  phone-number        date
0      Ronald Reyes  South Oroville  631-367-2892  1984-04-14
1      Scott Nguyen       Glenmoore  350-506-1497  1978-11-18
2     Joseph Rogers     Cherry Tree  315-937-6733  2012-11-13
3  Alisha Whitehead            Iola  870-884-0471  1998-02-04
4  Christopher Cook       Liverpool  370-595-5729  2017-10-30

【讨论】:

  • 这很奇怪。我安装了 Faker 2.0.5 但还是不行
  • 使用的是 ide 还是 jupyter?
  • 我正在使用 Pycharm
  • 我尝试在 CMD 提示符下运行代码。它给了我一个错误,说 (openpyxl) moudle 丢失了,所以我安装了它并设法让它在 CMD 提示符下工作,但它在 Pycharm 中仍然不起作用。你知道我怎样才能让它在 Pycharm 中也能工作吗?
  • 没关系。您的第一个解决方案成功了。我只是使用 pip 安装 Faker 2.0.5。这次我不得不从 Pycharm itslef 安装它。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
  • 2011-10-17
  • 2017-06-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多