i am working on Youtube API for Python: How to Create a Unique Data Portfolio Project
and i always got an error message while running this code:
import isodatevideo_df["durationSecs"]= video_df["duration"].apply(lambda x: isodate.parse_duration(x))video_df["durationSecs"]= video_df["durationSecs"].astype("timedelta64[s]")
error message is:
TypeError Traceback (most recent call last) Cell In[111], line 2 1 import isodate----> 2 video_df["durationSecs"]= video_df["duration"].apply(lambda x: isodate.parse_duration(x)) 3 video_df["durationSecs"]= video_df["durationSecs"].astype("timedelta64[s]")File /usr/local/lib/python3.11/site-packages/pandas/core/series.py:4764, in Series.apply(self, func, convert_dtype, args, by_row, **kwargs) 4629 def apply( 4630 self, 4631 func: AggFuncType, (...) 4636 **kwargs, 4637 ) -> DataFrame | Series: 4638 """ 4639 Invoke function on values of Series. 4640 (...) 4755 dtype: float64 4756 """ 4757 return SeriesApply( 4758 self, 4759 func, 4760 convert_dtype=convert_dtype, 4761 by_row=by_row, 4762 args=args, 4763 kwargs=kwargs,-> 4764 ).apply()File /usr/local/lib/python3.11/site-packages/pandas/core/apply.py:1209, in SeriesApply.apply(self) 1206 return self.apply_compat() 1208# self.func is Callable-> 1209 return self.apply_standard()File /usr/local/lib/python3.11/site-packages/pandas/core/apply.py:1289, in SeriesApply.apply_standard(self) 1283 # row-wise access 1284 # apply doesn't have a `na_action` keyword and for backward compat reasons 1285 # we need to give `na_action="ignore"` for categorical data. 1286 # TODO: remove the `na_action="ignore"` when that default has been changed in 1287 # Categorical (GH51645). 1288 action = "ignore" if isinstance(obj.dtype, CategoricalDtype) else None-> 1289 mapped = obj._map_values( 1290 mapper=curried, na_action=action, convert=self.convert_dtype 1291 ) 1293 if len(mapped) and isinstance(mapped[0], ABCSeries): 1294 # GH#43986 Need to do list(mapped) in order to get treated as nested 1295 # See also GH#25959 regarding EA support 1296 return obj._constructor_expanddim(list(mapped), index=obj.index)File /usr/local/lib/python3.11/site-packages/pandas/core/base.py:919, in IndexOpsMixin._map_values(self, mapper, na_action, convert) 916 arr = self._values 918 if isinstance(arr, ExtensionArray):--> 919 return arr.map(mapper, na_action=na_action) 921 return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)File /usr/local/lib/python3.11/site-packages/pandas/core/arrays/_mixins.py:80, in ravel_compat.<locals>.method(self, *args, **kwargs) 77 @wraps(meth) 78 def method(self, *args, **kwargs): 79 if self.ndim == 1:---> 80 return meth(self, *args, **kwargs) 82 flags = self._ndarray.flags 83 flat = self.ravel("K")File /usr/local/lib/python3.11/site-packages/pandas/core/arrays/datetimelike.py:723, in DatetimeLikeArrayMixin.map(self, mapper, na_action) 719 @ravel_compat 720 def map(self, mapper, na_action=None): 721 from pandas import Index--> 723 result = map_array(self, mapper, na_action=na_action) 724 result = Index(result) 726 if isinstance(result, ABCMultiIndex):File /usr/local/lib/python3.11/site-packages/pandas/core/algorithms.py:1814, in map_array(arr, mapper, na_action, convert) 1812 values = arr.astype(object, copy=False) 1813 if na_action is None:-> 1814 return lib.map_infer(values, mapper, convert=convert) 1815 else: 1816 return lib.map_infer_mask( 1817 values, mapper, mask=isna(values).view(np.uint8), convert=convert 1818 )File lib.pyx:2926, in pandas._libs.lib.map_infer()Cell In[111], line 2, in <lambda>(x) 1 import isodate----> 2 video_df["durationSecs"]= video_df["duration"].apply(lambda x: isodate.parse_duration(x)) 3 video_df["durationSecs"]= video_df["durationSecs"].astype("timedelta64[s]")File /usr/local/lib/python3.11/site-packages/isodate/isoduration.py:86, in parse_duration(datestring) 58 """ 59 Parses an ISO 8601 durations into datetime.timedelta or Duration objects. 60 (...) 83 days set to 0. 84 """ 85 if not isinstance(datestring, string_types):---> 86 raise TypeError("Expecting a string %r" % datestring) 87 match = ISO8601_PERIOD_REGEX.match(datestring) 88 if not match: 89 # try alternative format:TypeError: Expecting a string Timedelta('0 days 00:00:29')