Example #1
0
    def month_name(self, locale=None) -> 'ks.Series':
        """
        Return the month names of the series with specified locale.

        Parameters
        ----------
        locale : str, optional
            Locale determining the language in which to return the month name.
            Default is English locale.

        Returns
        -------
        Series
            Series of month names.

        Examples
        --------
        >>> series = ks.Series(pd.date_range(start='2018-01', freq='M', periods=3))
        >>> series
        0   2018-01-31
        1   2018-02-28
        2   2018-03-31
        Name: 0, dtype: datetime64[ns]

        >>> series.dt.month_name()
        0     January
        1    February
        2       March
        Name: 0, dtype: object
        """
        return _wrap_accessor_pandas(self, lambda x: x.dt.month_name(locale),
                                     StringType()).alias(self.name)
Example #2
0
    def day_name(self, locale=None) -> 'ks.Series':
        """
        Return the day names of the series with specified locale.

        Parameters
        ----------
        locale : str, optional
            Locale determining the language in which to return the day name.
            Default is English locale.

        Returns
        -------
        Series
            Series of day names.

        Examples
        --------
        >>> series = ks.Series(pd.date_range(start='2018-01-01', freq='D', periods=3))
        >>> series
        0   2018-01-01
        1   2018-01-02
        2   2018-01-03
        Name: 0, dtype: datetime64[ns]

        >>> series.dt.day_name()
        0       Monday
        1      Tuesday
        2    Wednesday
        Name: 0, dtype: object
        """
        return _wrap_accessor_pandas(self, lambda x: x.dt.day_name(locale),
                                     StringType()).alias(self.name)
Example #3
0
    def is_leap_year(self) -> 'ks.Series':
        """
        Boolean indicator if the date belongs to a leap year.

        A leap year is a year, which has 366 days (instead of 365) including
        29th of February as an intercalary day.
        Leap years are years which are multiples of four with the exception
        of years divisible by 100 but not by 400.

        Returns
        -------
        Series
             Booleans indicating if dates belong to a leap year.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor.

        >>> dates_series = ks.Series(pd.date_range("2012-01-01", "2015-01-01", freq="Y"))
        >>> dates_series
        0   2012-12-31
        1   2013-12-31
        2   2014-12-31
        Name: 0, dtype: datetime64[ns]

        >>> dates_series.dt.is_leap_year
        0     True
        1    False
        2    False
        Name: 0, dtype: bool
        """
        return _wrap_accessor_pandas(self, lambda s: s.dt.is_leap_year,
                                     BooleanType()).alias(self._data.name)
Example #4
0
    def normalize(self) -> 'ks.Series':
        """
        Convert times to midnight.

        The time component of the date-time is converted to midnight i.e.
        00:00:00. This is useful in cases, when the time does not matter.
        Length is unaltered. The timezones are unaffected.

        This method is available on Series with datetime values under
        the ``.dt`` accessor, and directly on Datetime Array.

        Returns
        -------
        Series
            The same type as the original data. Series will have the same
            name and index.

        See Also
        --------
        floor : Floor the series to the specified freq.
        ceil : Ceil the series to the specified freq.
        round : Round the series to the specified freq.

        Examples
        --------
        >>> series = ks.Series(pd.Series(pd.date_range('2012-1-1 12:45:31', periods=3, freq='M')))
        >>> series.dt.normalize()
        0   2012-01-31
        1   2012-02-29
        2   2012-03-31
        Name: 0, dtype: datetime64[ns]
        """
        return _wrap_accessor_pandas(self, lambda x: x.dt.normalize(),
                                     TimestampType()).alias(self.name)
Example #5
0
    def is_month_end(self) -> 'ks.Series':
        """
        Indicates whether the date is the last day of the month.

        Returns
        -------
        Series
            For Series, returns a Series with boolean values.

        See Also
        --------
        is_month_start : Return a boolean indicating whether the date
            is the first day of the month.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor.

        >>> s = ks.Series(pd.date_range("2018-02-27", periods=3))
        >>> s
        0   2018-02-27
        1   2018-02-28
        2   2018-03-01
        Name: 0, dtype: datetime64[ns]

        >>> s.dt.is_month_end
        0    False
        1     True
        2    False
        Name: 0, dtype: bool
        """
        return _wrap_accessor_pandas(self, lambda s: s.dt.is_month_end,
                                     BooleanType()).alias(self._data.name)
Example #6
0
    def is_year_end(self) -> 'ks.Series':
        """
        Indicate whether the date is the last day of the year.

        Returns
        -------
        Series
            The same type as the original data with boolean values. Series will
            have the same name and index.

        See Also
        --------
        is_year_start : Similar property indicating the start of the year.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor.

        >>> dates = ks.Series(pd.date_range("2017-12-30", periods=3))
        >>> dates
        0   2017-12-30
        1   2017-12-31
        2   2018-01-01
        Name: 0, dtype: datetime64[ns]

        >>> dates.dt.is_year_end
        0    False
        1     True
        2    False
        Name: 0, dtype: bool
        """
        return _wrap_accessor_pandas(self, lambda s: s.dt.is_year_end,
                                     BooleanType()).alias(self._data.name)
Example #7
0
 def quarter(self) -> "ks.Series":
     """
     The quarter of the date.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.quarter, LongType()).alias(
         self._data.name
     )
Example #8
0
 def daysinmonth(self) -> "ks.Series":
     """
     The number of days in the month.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.daysinmonth, LongType()).alias(
         self._data.name
     )
Example #9
0
 def dayofyear(self) -> "ks.Series":
     """
     The ordinal day of the year.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.dayofyear, LongType()).alias(
         self._data.name
     )
Example #10
0
 def strftime(self, date_format) -> 'ks.Series':
     """
     Convert to a String Series using specified date_format.
     """
     return _wrap_accessor_pandas(self,
                                  lambda x: x.dt.strftime(date_format),
                                  StringType()).alias(self.name)
Example #11
0
    def isdecimal(self) -> 'ks.Series':
        """
        Check whether all characters in each string are decimals.

        This is equivalent to running the Python string method
        :func:`str.isdecimal` for each element of the Series/Index.
        If a string has zero characters, False is returned for that check.
        """
        return _wrap_accessor_pandas(self, lambda x: x.str.isdecimal(),
                                     BooleanType()).alias(self.name)
Example #12
0
    def ceil(self, freq, *args, **kwargs) -> 'ks.Series':
        """
        Perform ceil operation on the data to the specified freq.

        Parameters
        ----------
        freq : str or Offset
            The frequency level to round the index to. Must be a fixed
            frequency like 'S' (second) not 'ME' (month end).

        nonexistent : 'shift_forward', 'shift_backward, 'NaT', timedelta, default 'raise'
            A nonexistent time does not exist in a particular timezone
            where clocks moved forward due to DST.

            - 'shift_forward' will shift the nonexistent time forward to the
              closest existing time
            - 'shift_backward' will shift the nonexistent time backward to the
              closest existing time
            - 'NaT' will return NaT where there are nonexistent times
            - timedelta objects will shift nonexistent times by the timedelta
            - 'raise' will raise an NonExistentTimeError if there are
              nonexistent times

            .. note:: this option only works with pandas 0.24.0+

        Returns
        -------
        Series
            a Series with the same index for a Series.

        Raises
        ------
        ValueError if the `freq` cannot be converted.

        Examples
        --------
        >>> series = ks.Series(pd.date_range('1/1/2018 11:59:00', periods=3, freq='min'))
        >>> series
        0   2018-01-01 11:59:00
        1   2018-01-01 12:00:00
        2   2018-01-01 12:01:00
        Name: 0, dtype: datetime64[ns]

        >>> series.dt.ceil("H")
        0   2018-01-01 12:00:00
        1   2018-01-01 12:00:00
        2   2018-01-01 13:00:00
        Name: 0, dtype: datetime64[ns]
        """
        return _wrap_accessor_pandas(
            self,
            lambda x: x.dt.ceil(freq),
            TimestampType()
        ).alias(self.name)
Example #13
0
    def get(self, i) -> 'ks.Series':
        """
        Extract element from each string in the Series/Index at the
        specified position.

        Parameters
        ----------
        i : int
            Position of element to extract.

        Returns
        -------
        Series of objects
        """
        return _wrap_accessor_pandas(self, lambda x: x.str.get(i),
                                     StringType()).alias(self.name)
Example #14
0
    def strftime(self, date_format) -> 'ks.Series':
        """
        Convert to a string Series using specified date_format.

        Return an series of formatted strings specified by date_format, which
        supports the same string format as the python standard library. Details
        of the string format can be found in python string format
        doc.

        Parameters
        ----------
        date_format : str
            Date format string (e.g. "%%Y-%%m-%%d").

        Returns
        -------
        Series
            Series of formatted strings.

        See Also
        --------
        to_datetime : Convert the given argument to datetime.
        normalize : Return series with times to midnight.
        round : Round the series to the specified freq.
        floor : Floor the series to the specified freq.

        Examples
        --------
        >>> series = ks.Series(pd.date_range(pd.Timestamp("2018-03-10 09:00"),
        ...                                  periods=3, freq='s'))
        >>> series
        0   2018-03-10 09:00:00
        1   2018-03-10 09:00:01
        2   2018-03-10 09:00:02
        Name: 0, dtype: datetime64[ns]

        >>> series.dt.strftime('%B %d, %Y, %r')
        0    March 10, 2018, 09:00:00 AM
        1    March 10, 2018, 09:00:01 AM
        2    March 10, 2018, 09:00:02 AM
        Name: 0, dtype: object
        """
        return _wrap_accessor_pandas(
            self,
            lambda x: x.dt.strftime(date_format),
            StringType()
        ).alias(self.name)
Example #15
0
    def is_quarter_end(self) -> "ks.Series":
        """
        Indicator for whether the date is the last day of a quarter.

        Returns
        -------
        is_quarter_end : Series
            The same type as the original data with boolean values. Series will
            have the same name and index.

        See Also
        --------
        quarter : Return the quarter of the date.
        is_quarter_start : Similar property indicating the quarter start.

        Examples
        --------
        This method is available on Series with datetime values under
        the ``.dt`` accessor.

        >>> df = ks.DataFrame({'dates': pd.date_range("2017-03-30",
        ...                   periods=4)})
        >>> df
               dates
        0 2017-03-30
        1 2017-03-31
        2 2017-04-01
        3 2017-04-02

        >>> df.dates.dt.quarter
        0    1
        1    1
        2    2
        3    2
        Name: dates, dtype: int64

        >>> df.dates.dt.is_quarter_start
        0    False
        1    False
        2     True
        3    False
        Name: dates, dtype: bool
        """
        return _wrap_accessor_pandas(self, lambda s: s.dt.is_quarter_end, BooleanType()).alias(
            self._data.name
        )
Example #16
0
    def rstrip(self, to_strip=None) -> 'ks.Series':
        """
        Remove trailing characters.

        Strip whitespaces (including newlines) or a set of specified
        characters from each string in the Series/Index from right side.
        Equivalent to :func:`str.rstrip`.

        Parameters
        ----------
        to_strip : str
            Specifying the set of characters to be removed. All combinations
            of this set of characters will be stripped. If None then
            whitespaces are removed.

        Returns
        -------
        Series of str
        """
        return _wrap_accessor_pandas(self, lambda x: x.str.rstrip(to_strip),
                                     StringType()).alias(self.name)
Example #17
0
    def endswith(self, pattern, na=np.NaN) -> 'ks.Series':
        """
        Test if the end of each string element matches a pattern.

        Equivalent to :func:`str.endswith`.

        Parameters
        ----------
        pattern : str
            Character sequence. Regular expressions are not accepted.
        na : object, defulat NaN
            Object shown if element is not a string.

        Returns
        -------
        Series of bool
            Koalas Series of booleans indicating whether the given pattern
            matches the end of each string element.
        """
        return _wrap_accessor_pandas(self,
                                     lambda x: x.str.endswith(pattern, na),
                                     BooleanType()).alias(self.name)
Example #18
0
    def dayofweek(self) -> "ks.Series":
        """
        The day of the week with Monday=0, Sunday=6.

        Return the day of the week. It is assumed the week starts on
        Monday, which is denoted by 0 and ends on Sunday which is denoted
        by 6. This method is available on both Series with datetime
        values (using the `dt` accessor).

        Returns
        -------
        Series
            Containing integers indicating the day number.

        See Also
        --------
        Series.dt.dayofweek : Alias.
        Series.dt.weekday : Alias.
        Series.dt.day_name : Returns the name of the day of the week.

        Examples
        --------
        >>> s = ks.from_pandas(pd.date_range('2016-12-31', '2017-01-08', freq='D').to_series())
        >>> s.dt.dayofweek
        2016-12-31    5
        2017-01-01    6
        2017-01-02    0
        2017-01-03    1
        2017-01-04    2
        2017-01-05    3
        2017-01-06    4
        2017-01-07    5
        2017-01-08    6
        Name: 0, dtype: int64
        """
        return _wrap_accessor_pandas(self, lambda s: s.dt.dayofweek, LongType()).alias(
            self._data.name
        )
Example #19
0
 def is_month_start(self) -> 'ks.Series':
     """
     Indicates whether the date is the first day of the month.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.is_month_start,
                                  BooleanType()).alias(self._data.name)
Example #20
0
 def swapcase(self) -> 'ks.Series':
     """
     Convert strings in the Series/Index to be swapcased.
     """
     return _wrap_accessor_pandas(self, lambda x: x.str.swapcase(),
                                  StringType()).alias(self.name)
Example #21
0
 def upper(self) -> 'ks.Series':
     """
     Convert strings in the Series/Index to all uppercase.
     """
     return _wrap_accessor_pandas(self, lambda x: x.str.upper(),
                                  StringType()).alias(self.name)
Example #22
0
 def capitalize(self) -> 'ks.Series':
     """
     Convert Strings in the series to be capitalized.
     """
     return _wrap_accessor_pandas(self, lambda x: x.str.capitalize(),
                                  StringType()).alias(self.name)
Example #23
0
 def is_quarter_start(self) -> 'ks.Series':
     """
     Indicator for whether the date is the first day of a quarter.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.is_quarter_start,
                                  BooleanType()).alias(self._data.name)
Example #24
0
 def microsecond(self) -> 'ks.Series':
     """
     The microseconds of the datetime.
     """
     return _wrap_accessor_pandas(self, lambda x: x.dt.microsecond,
                                  LongType()).alias(self.name)
Example #25
0
 def day_name(self, locale=None) -> 'ks.Series':
     """
     Return the day names of the DateTimeIndex with specified locale.
     """
     return _wrap_accessor_pandas(self, lambda x: x.dt.day_name(locale),
                                  StringType()).alias(self.name)
Example #26
0
 def ceil(self, freq) -> 'ks.Series':
     """
     Perform ceil operation on the data to the specified freq.
     """
     return _wrap_accessor_pandas(self, lambda x: x.dt.ceil(freq),
                                  TimestampType()).alias(self.name)
Example #27
0
 def is_year_end(self) -> 'ks.Series':
     """
     Indicate whether the date is the last day of the year.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.is_year_end,
                                  BooleanType()).alias(self._data.name)
Example #28
0
 def normalize(self) -> 'ks.Series':
     """
     Convert times to midnight.
     """
     return _wrap_accessor_pandas(self, lambda x: x.dt.normalize(),
                                  TimestampType()).alias(self.name)
Example #29
0
 def is_leap_year(self) -> 'ks.Series':
     """
     Boolean indicator if the date belongs to a leap year.
     """
     return _wrap_accessor_pandas(self, lambda s: s.dt.is_leap_year,
                                  BooleanType()).alias(self._data.name)