When I run this ,
nfl_frame.columns
then , I have this output:
Index(['Rank ', 'Team ', 'Won ', 'Lost ', 'Tied* ', 'Pct. ', 'First Season ',
'Total Games ', 'Conference'],
dtype='object')
But, when I write :
nfl_frame.Rank
it shows the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-180-49fcdc59c710> in <module>()
----> 1 nfl_frame.Rank
C:\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
2148 return self[name]
2149 raise AttributeError("'%s' object has no attribute '%s'" %
-> 2150 (type(self).__name__, name))
2151
2152 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'Rank'
*I am using Python 3.4 and Ipython notebook.
Related
ISL_eventPassdf[ISL_eventPassdf["match_id"].isin([3817897, 3813305])]["match_id"].drop_duplicates()
Series([], Name: match_Id, dtype: int64)\
ISL_FINAL_Data =ISL_eventPassdf[ISL_eventPassdf["match_id"].isin([3817897, 3813305])]["match_id"]
ISL_FINAL_Data.pivot_table(values="type.id", index="player.name", columns="pass.recipient.name", aggfunc="count")
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_11460/1068599328.py in
----> 1 ISL_FINAL_Data.pivot_table(values="type.id", index="player.name", columns="pass.recipient.name", aggfunc="count")
C:\Python\Python310\lib\site-packages\pandas\core\generic.py in getattr(self, name)
5905 ):
5906 return self[name]
-> 5907 return object.getattribute(self, name)
5908
5909 def setattr(self, name: str, value) -> None:
AttributeError: 'Series' object has no attribute 'pivot_table'
please help me to fix this
error shows 'Series' object has no attribute 'pivot_table'
would you please tell me why when i use the following script:
from allennlp.common import JsonDict
i get the following error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-58adc5745662> in <module>()
----> 1 from allennlp.common import JsonDict
10 frames
/usr/local/lib/python3.7/dist-packages/overrides/signature.py in ensure_all_kwargs_defined_in_sub(super_sig, sub_sig, super_type_hints, sub_type_hints, check_first_parameter, method_name)
134 name, True, sub_has_var_kwargs, sub_sig, super_param
135 ):
--> 136 raise TypeError(f"{method_name}: `{name}` is not present.")
137 elif name in sub_sig.parameters and super_param.kind != Parameter.VAR_KEYWORD:
138 sub_index = list(sub_sig.parameters.keys()).index(name)
TypeError: FileLock.acquire: `poll_intervall` is not present.
I am learning about python/pandas attributes in a Series. I can get it to display the min and max values, but I want to display the min and max index values and I get an error message.
google.min()
49.95
google.max()
782.22
google.idmin()
AttributeError Traceback (most recent
call last) in
----> 1 google.idmin(True)
/opt/anaconda3/envs/pandas_playground/lib/python3.8/site-packages/pandas/core/generic.py
in getattr(self, name) 5272 if
self._info_axis._can_hold_identifiers_and_holds_name(name): 5273
return self[name]
-> 5274 return object.getattribute(self, name) 5275 5276 def setattr(self, name: str, value) -> None:
AttributeError: 'Series' object has no attribute 'idmin'
After some searching, I found I was simply using the wrong methods.
idxmin and idxmax work just fine.
google.idxmax()
3011
google.idxmin()
11
I am getting the following error and I am not sure what it is. Can you please help me identify what is causing this error?
def determine_device_type(*args, **kwargs):
device_name = str(args[0])
#print(device_name)
if re.search(r'^\w+c(\d\d|\w\w|\d\d\d\d)$', device_name):
print(device_name, ' --> ', 'Cisco')
return 'Cisco'
if re.search(r'^\w+r(\d\d|\w\w|\d\d\d\d)$', device_name):
print(device_name, ' --> ', 'Riverbed')
return 'Riverbed'
if re.search(r'^\w+j(\d\d|\w\w|\d\d\d\d)$', device_name):
print(device_name, ' --> ', 'Juniper')
return 'Juniper'
return ''
vendor = df['DEVICE'].apply(determine_device_type)
df.insert(3, 'VENDOR', vendor)
Error
ValueError Traceback (most recent call last)
<ipython-input-42-8b32a12d4761> in <module>()
21
22 vendor = df['MDN_DEVICE'].apply(determine_device_type)
---> 23 df.insert(3, 'VENDOR', vendor)
24 df
C:\Continuum\anaconda3\lib\site-packages\pandas\core\frame.py in insert(self, loc, column, value, allow_duplicates)
2611 value = self._sanitize_column(column, value, broadcast=False)
2612 self._data.insert(loc, column, value,
-> 2613 allow_duplicates=allow_duplicates)
2614
2615 def assign(self, **kwargs):
C:\Continuum\anaconda3\lib\site-packages\pandas\core\internals.py in insert(self, loc, item, value, allow_duplicates)
4061 if not allow_duplicates and item in self.items:
4062 # Should this be a different kind of error??
-> 4063 raise ValueError('cannot insert {}, already exists'.format(item))
4064
4065 if not isinstance(loc, int):
ValueError: cannot insert VENDOR, already exists
It seems you already have a 'VENDOR' column. You can use the df.head() to confirm. To avoid the error, drop the column before inserting.
df.drop(columns=['VENDOR']).insert(3, 'VENDOR', vendor)
I am new to python. Just following the tutorial: https://www.hackerearth.com/practice/machine-learning/machine-learning-projects/python-project/tutorial/
This is the dataframe miss:
miss = train.isnull().sum()/len(train)
miss = miss[miss>0]
miss.sort_values(inplace = True)
miss
Electrical 0.000685
MasVnrType 0.005479
MasVnrArea 0.005479
BsmtQual 0.025342
BsmtCond 0.025342
BsmtFinType1 0.025342
BsmtExposure 0.026027
BsmtFinType2 0.026027
GarageCond 0.055479
GarageQual 0.055479
GarageFinish 0.055479
GarageType 0.055479
GarageYrBlt 0.055479
LotFrontage 0.177397
FireplaceQu 0.472603
Fence 0.807534
Alley 0.937671
MiscFeature 0.963014
PoolQC 0.995205
dtype: float64
Now I just want to visualize those missing values"
#visualising missing values
miss = miss.to_frame()
miss.columns = ['count']
miss.index.names = ['Name']
miss['Name'] = miss.index
And this is the error I got:
AttributeError Traceback (most recent call last)
<ipython-input-42-cd3b25e8862a> in <module>()
1 #visualising missing values
----> 2 miss = miss.to_frame()
C:\Users\Username\AppData\Local\Continuum\Anaconda3\lib\site-packages\pandas\core\generic.py in __getattr__(self, name)
2742 if name in self._info_axis:
2743 return self[name]
-> 2744 return object.__getattribute__(self, name)
2745
2746 def __setattr__(self, name, value):
AttributeError: 'DataFrame' object has no attribute 'to_frame'
What am I missing here?
Check print(type(miss)) it should be <class 'pandas.core.series.Series'>
You have is dataframe, somewhere in the code you are doing wrong.
df = pd.DataFrame()
df.to_frame()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\UR_NAME\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 3614, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'to_frame'
I traced the tutorial, and below is the order flow
train = pd.read_csv("train.csv")
print(type(train)) # <class 'pandas.core.frame.DataFrame'>
miss = train.isnull().sum()/len(train)
print(type(miss)) # <class 'pandas.core.series.Series'>
miss = train.isnull().sum()/len(train) converts in into pandas.core.series.Series from pandas.core.frame.DataFrame
You are probably messed code at this place.
If you use Notebook while the current cell is running, "miss" is converted to a data frame so that the output is displayed the first time. If you run the cell again, you will get an/the error because it is already a data frame. So run the previous cell again and then run the current cell to fix the problem. The notebook itself works this way.