'Series Error when using .dtypes() for pandas
I am relatively new to Python / Pandas and I am trying to print out the type of values for each column in my data frame. However, when I try to use the .dtypes() function I am getting a series error.
Here is some of the code I am using:
file = pd.read_csv('Nudge.csv', sep=",")
data = pd.DataFrame({'SR_ID': file['SR ID'], 'On_Time_%': file['On-Time %'], '#_Tardy': file['# Unex Tardy'],
'Tardy_Rank': file['Tardy Rank']})
new_data = data.sort_values(by='On_Time_%', ascending=True)
# print(new_data)
print(data.dtypes())
TypeError: 'Series' object is not callable
Solution 1:[1]
dtypes is not a function rather a variable. It should be called like this,
print(data.dtypes)
Solution 2:[2]
Just use data.dtypes instead of data.dtypes(), as it is an attribute and no function.
This will return something like:
ID object
Year object
Month object
Amount object
dtype: object
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alagappan |
| Solution 2 | Marco_CH |
