'int' object has no attribute 'head'
时间: 2023-09-25 16:09:25 浏览: 108
This error occurs when you try to call the method 'head' on an integer object. The 'head' method is not available for integers as it is a method of Pandas DataFrame or Series objects which are used for data manipulation and analysis.
For example, if you have a variable 'x' that is an integer, calling 'x.head()' would result in this error. To fix this, you need to make sure that you are calling the 'head' method on a Pandas DataFrame or Series object.
Here's an example of how to use the 'head' method on a Pandas DataFrame:
```python
import pandas as pd
# create a dataframe
df = pd.DataFrame({'col1': [1, 2, 3], 'col2': ['a', 'b', 'c']})
# call the head method to get the first 5 rows
df.head()
```
This will output the first 5 rows of the dataframe:
```
col1 col2
0 1 a
1 2 b
2 3 c
```
阅读全文