Pandas Series: dt.to_period() function
Series.dt.to_period() function
Cast to PeriodArray/Index at a particular frequency.
Converts DatetimeArray/Index to PeriodArray/Index.
Syntax:
Series.dt.to_period(self, *args, **kwargs)
Parameter:
Name | Description | Type / Default Value | Required / Optional |
---|---|---|---|
freq | One of pandas’ offset strings or an Offset object. Will be inferred by default. | str or Offset | Optional |
Returns: PeriodArray/Index
Raises: ValueError
When converting a DatetimeArray/Index with non-regular values, so that a frequency cannot be inferred.
Example:
Download the Pandas Series Notebooks from here.
Previous: Series.dt.is_leap_year() function
Next: Series.dt.to_pydatetime() function
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework