submodules không ngầm nhập khẩu, và phải rõ ràng tuyên bố, nhưng tôi đang làm cho một rõ ràng cuộc gọi đến pd.Series
submodule, không phải là tôi?AttributeError: đối tượng module không có thuộc tính "Series". Mã làm việc trong ipython
Bất kể, không nên import pandas as pd
cho phép pd.Series
được gọi? Mã sau hoạt động hoàn hảo trong iPython, nhưng không thành công khi được thực thi từ tập lệnh.
#!/usr/bin/env/python2.7
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np
counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
Kết quả trong:
[email protected] ~/src/stats $ python pandas.py
Traceback (most recent call last):
File "pandas.py", line 3, in <module>
import pandas as pd
File "/home/tyler/src/stats/pandas.py", line 6, in <module>
counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
AttributeError: 'module' object has no attribute 'Series'
ở đâu tôi đi sai?
Lưu ý rằng điều này chỉ có vẻ là một vấn đề trong Python 2.7.x không 3.x. –