Tag Archives: Python AttributeError

How to Solve Python AttributeError: ‘module’ object has no attribute ‘xxx’

Python script error attributeerror: ‘module’ object has no attribute ‘xxx’ solution

when you encounter a few problems, you should pay attention to the same problem when you don’t ask for a solution

1. When naming py script, it should not be the same as the reserved word and module name of Python
(it is not easy to notice when naming files)
2 Delete the. PyC file of the library (because the. PyC file will be generated every time the PY script runs; if the. PyC file has been generated, if the code is not updated, the runtime will still go PyC, so you need to delete the. PyC file), rerun the code, or find an environment where you can run the code and copy and replace the. PyC file of the current machine Import questions </ font> </ font>

How to Solve attributeerror: ‘list’ object has no attribute ‘shape‘


AttributeError: ‘list’ object has no attribute ‘shape’

Property error: the ‘list’ object does not have the property ‘shape’


Use numpy or panda np.array Or dataframe has shape, which can be multi-dimensional, while list is one-dimensional and cannot be converted

If conversion is needed, list is converted to dataframe. Example:

a = [['a', 'b', 'c'], ['1', '2', '3'], ['张三', '张三', '张三']]
df = pd.DataFrame(a, columns=['one', 'two', 'three'])

List to numpy example:

a = [['a', 'b', 'c'], ['1', '2', '3'], ['张三', '张三', '张三']]
data = np.array(a)

Note: shape is a dimension. Only data frame and matrix have dimensions, while list is a slice single dimension