前提・実現したいこと
こちらのコードをJupyter Notebookにコピーしながら実行していたところ、以下のようなエラーが出てしまいました。
DataFrameがSeriesとしてうまく認識されていないためこのようなエラーが出ているのだと思うのですが、どのようにコードを修正したらよいかわからずこちらに質問をさせていただきました。
大変お手数をお掛けしますが、解決方法についてご存じの方がいらっしゃいましたらご教示いただけますと幸いです。
発生している問題・エラーメッセージ
AttributeError Traceback (most recent call last) <ipython-input-10-60593f14d96f> in <module> ----> 1 train_df['x_min'] = train_df.apply(lambda row: (row.x_min)/row.width, axis =1) 2 train_df['y_min'] = train_df.apply(lambda row: (row.y_min)/row.height, axis =1) 3 4 train_df['x_max'] = train_df.apply(lambda row: (row.x_max)/row.width, axis =1) 5 train_df['y_max'] = train_df.apply(lambda row: (row.y_max)/row.height, axis =1) ~/home/user/libraries/Miniconda3/envs/test/lib/python3.6/site-packages/pandas/core/frame.py in apply(self, func, axis, raw, result_type, args, **kwds) 7550 kwds=kwds, 7551 ) -> 7552 return op.get_result() 7553 7554 def applymap(self, func) -> "DataFrame": ~/home/user/libraries/Miniconda3/envs/test/lib/python3.6/site-packages/pandas/core/apply.py in get_result(self) 183 return self.apply_raw() 184 --> 185 return self.apply_standard() 186 187 def apply_empty_result(self): ~/home/user/libraries/Miniconda3/envs/test/lib/python3.6/site-packages/pandas/core/apply.py in apply_standard(self) 274 275 def apply_standard(self): --> 276 results, res_index = self.apply_series_generator() 277 278 # wrap results ~/home/user/libraries/Miniconda3/envs/test/lib/python3.6/site-packages/pandas/core/apply.py in apply_series_generator(self) 303 for i, v in enumerate(series_gen): 304 # ignore SettingWithCopy here in case the user mutates --> 305 results[i] = self.f(v) 306 if isinstance(results[i], ABCSeries): 307 # If we have a view on v, we need to make a copy because <ipython-input-10-60593f14d96f> in <lambda>(row) ----> 1 train_df['x_min'] = train_df.apply(lambda row: (row.x_min)/row.width, axis =1) 2 train_df['y_min'] = train_df.apply(lambda row: (row.y_min)/row.height, axis =1) 3 4 train_df['x_max'] = train_df.apply(lambda row: (row.x_max)/row.width, axis =1) 5 train_df['y_max'] = train_df.apply(lambda row: (row.y_max)/row.height, axis =1) ~/home/user/libraries/Miniconda3/envs/test/lib/python3.6/site-packages/pandas/core/generic.py in __getattr__(self, name) 5139 if self._info_axis._can_hold_identifiers_and_holds_name(name): 5140 return self[name] -> 5141 return object.__getattribute__(self, name) 5142 5143 def __setattr__(self, name: str, value) -> None: AttributeError: 'Series' object has no attribute 'width'
該当のソースコード
!pip install --upgrade seaborn import numpy as np, pandas as pd from glob import glob import shutil, os import matplotlib.pyplot as plt from sklearn.model_selection import GroupKFold from tqdm.notebook import tqdm import seaborn as sns #dim = 512 #512, 256, 'original' fold = 4 train_df = pd.read_csv(f'./train.csv') train_df.head() train_df['image_path'] = f'./train_1_resized_jpeg/'+train_df.image_id+('.jpeg')#if dim!='original' else '.jpg') train_df.head() #train_df = train_df[train_df.class_id!=14].reset_index(drop = True) train_df['x_min'] = train_df.apply(lambda row: (row.x_min)/row.width, axis =1) train_df['y_min'] = train_df.apply(lambda row: (row.y_min)/row.height, axis =1) train_df['x_max'] = train_df.apply(lambda row: (row.x_max)/row.width, axis =1) train_df['y_max'] = train_df.apply(lambda row: (row.y_max)/row.height, axis =1) train_df['x_mid'] = train_df.apply(lambda row: (row.x_max+row.x_min)/2, axis =1) train_df['y_mid'] = train_df.apply(lambda row: (row.y_max+row.y_min)/2, axis =1) train_df['w'] = train_df.apply(lambda row: (row.x_max-row.x_min), axis =1) train_df['h'] = train_df.apply(lambda row: (row.y_max-row.y_min), axis =1) train_df['area'] = train_df['w']*train_df['h'] train_df.head()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/02/10 07:26