언빌리버블티

[Python] Pandas 시리즈 접근자 ( dt. str. cat. sparse. ) 본문

Language/Python

[Python] Pandas 시리즈 접근자 ( dt. str. cat. sparse. )

나는 정은 2022. 10. 12. 00:27

Pandas 시리즈 접근자

dtype에 따라 시리즈에 접근할 수 있는 다양한 접근자를 제공하고 있다.
시리즈 내에서 특정 데이터 유형에만 적용되는 별도의 네임스페이스이다.

Data Type
Accessor
Datetime
dt
String
str
Categorical
cat
Sparse
sparse

 

Datetime properties

 
Series.dt.date
Returns numpy array of python datetime.date objects.
Series.dt.time
Returns numpy array of datetime.time objects.
Series.dt.timetz
Returns numpy array of datetime.time objects with timezones.
Series.dt.year
The year of the datetime.
Series.dt.month
The month as January=1, December=12.
Series.dt.day
The day of the datetime.
Series.dt.hour
The hours of the datetime.
Series.dt.minute
The minutes of the datetime.
Series.dt.second
The seconds of the datetime.
Series.dt.microsecond
The microseconds of the datetime.
Series.dt.nanosecond
The nanoseconds of the datetime.
Series.dt.week
(DEPRECATED) The week ordinal of the year according to the ISO 8601 standard.
Series.dt.weekofyear
(DEPRECATED) The week ordinal of the year according to the ISO 8601 standard.
Series.dt.dayofweek
The day of the week with Monday=0, Sunday=6.
Series.dt.day_of_week
The day of the week with Monday=0, Sunday=6.
Series.dt.weekday
The day of the week with Monday=0, Sunday=6.
Series.dt.dayofyear
The ordinal day of the year.
Series.dt.day_of_year
The ordinal day of the year.
Series.dt.quarter
The quarter of the date.
Series.dt.is_month_start
Indicates whether the date is the first day of the month.
Series.dt.is_month_end
Indicates whether the date is the last day of the month.
Series.dt.is_quarter_start
Indicator for whether the date is the first day of a quarter.
Series.dt.is_quarter_end
Indicator for whether the date is the last day of a quarter.
Series.dt.is_year_start
Indicate whether the date is the first day of a year.
Series.dt.is_year_end
Indicate whether the date is the last day of the year.
Series.dt.is_leap_year
Boolean indicator if the date belongs to a leap year.
Series.dt.daysinmonth
The number of days in the month.
Series.dt.days_in_month
The number of days in the month.
Series.dt.tz
Return the timezone.
Series.dt.freq
Return the frequency object for this PeriodArray.

String accessor

Series.str을 사용하여 문자열 시리즈의 값에 액세스하고 여러 가지 메서드를 적용할 수 있다.

Series.str.capitalize()
Convert strings in the Series/Index to be capitalized.
Series.str.casefold()
Convert strings in the Series/Index to be casefolded.
Series.str.cat([others, sep, na_rep, join])
Concatenate strings in the Series/Index with given separator.
Series.str.center(width[, fillchar])
Pad left and right side of strings in the Series/Index.
Series.str.contains(pat[, case, flags, na, ...])
Test if pattern or regex is contained within a string of a Series or Index.
Series.str.count(pat[, flags])
Count occurrences of pattern in each string of the Series/Index.
Series.str.decode(encoding[, errors])
Decode character string in the Series/Index using indicated encoding.
Series.str.encode(encoding[, errors])
Encode character string in the Series/Index using indicated encoding.
Series.str.endswith(pat[, na])
Test if the end of each string element matches a pattern.
Series.str.extract(pat[, flags, expand])
Extract capture groups in the regex pat as columns in a DataFrame.
Series.str.extractall(pat[, flags])
Extract capture groups in the regex pat as columns in DataFrame.
Series.str.find(sub[, start, end])
Return lowest indexes in each strings in the Series/Index.
Series.str.findall(pat[, flags])
Find all occurrences of pattern or regular expression in the Series/Index.
Series.str.fullmatch(pat[, case, flags, na])
Determine if each string entirely matches a regular expression.
Series.str.get(i)
Extract element from each component at specified position or with specified key.
Series.str.index(sub[, start, end])
Return lowest indexes in each string in Series/Index.
Series.str.join(sep)
Join lists contained as elements in the Series/Index with passed delimiter.
Series.str.len()
Compute the length of each element in the Series/Index.
Series.str.ljust(width[, fillchar])
Pad right side of strings in the Series/Index.
Series.str.lower()
Convert strings in the Series/Index to lowercase.
Series.str.lstrip([to_strip])
Remove leading characters.
Series.str.match(pat[, case, flags, na])
Determine if each string starts with a match of a regular expression.
Series.str.normalize(form)
Return the Unicode normal form for the strings in the Series/Index.
Series.str.pad(width[, side, fillchar])
Pad strings in the Series/Index up to width.
Series.str.partition([sep, expand])
Split the string at the first occurrence of sep.
Series.str.removeprefix(prefix)
Remove a prefix from an object series.
Series.str.removesuffix(suffix)
Remove a suffix from an object series.
Series.str.repeat(repeats)
Duplicate each string in the Series or Index.
Series.str.replace(pat, repl[, n, case, ...])
Replace each occurrence of pattern/regex in the Series/Index.
Series.str.rfind(sub[, start, end])
Return highest indexes in each strings in the Series/Index.
Series.str.rindex(sub[, start, end])
Return highest indexes in each string in Series/Index.
Series.str.rjust(width[, fillchar])
Pad left side of strings in the Series/Index.
Series.str.rpartition([sep, expand])
Split the string at the last occurrence of sep.
Series.str.rstrip([to_strip])
Remove trailing characters.
Series.str.slice([start, stop, step])
Slice substrings from each element in the Series or Index.
Series.str.slice_replace([start, stop, repl])
Replace a positional slice of a string with another value.
Series.str.split([pat, n, expand, regex])
Split strings around given separator/delimiter.
Series.str.rsplit([pat, n, expand])
Split strings around given separator/delimiter.
Series.str.startswith(pat[, na])
Test if the start of each string element matches a pattern.
Series.str.strip([to_strip])
Remove leading and trailing characters.
Series.str.swapcase()
Convert strings in the Series/Index to be swapcased.
Series.str.title()
Convert strings in the Series/Index to titlecase.
Series.str.translate(table)
Map all characters in the string through the given mapping table.
Series.str.upper()
Convert strings in the Series/Index to uppercase.
Series.str.wrap(width, **kwargs)
Wrap strings in Series/Index at specified line width.
Series.str.zfill(width)
Pad strings in the Series/Index by prepending '0' characters.
Series.str.isalnum()
Check whether all characters in each string are alphanumeric.
Series.str.isalpha()
Check whether all characters in each string are alphabetic.
Series.str.isdigit()
Check whether all characters in each string are digits.
Series.str.isspace()
Check whether all characters in each string are whitespace.
Series.str.islower()
Check whether all characters in each string are lowercase.
Series.str.isupper()
Check whether all characters in each string are uppercase.
Series.str.istitle()
Check whether all characters in each string are titlecase.
Series.str.isnumeric()
Check whether all characters in each string are numeric.
Series.str.isdecimal()
Check whether all characters in each string are decimal.
Series.str.get_dummies([sep])
Return DataFrame of dummy/indicator variables for Series.

Categorical accessor

범주형 타입의 특정 메서드 및 속성은 Series.cat 로 접근할 수 있다.

Series.cat.categories
The categories of this categorical.
Series.cat.ordered
Whether the categories have an ordered relationship.
Series.cat.codes
Return Series of codes as well as the index.
Series.cat.rename_categories(*args, **kwargs)
Rename categories.
Series.cat.reorder_categories(*args, **kwargs)
Reorder categories as specified in new_categories.
Series.cat.add_categories(*args, **kwargs)
Add new categories.
Series.cat.remove_categories(*args, **kwargs)
Remove the specified categories.
Series.cat.remove_unused_categories(*args, ...)
Remove categories which are not used.
Series.cat.set_categories(*args, **kwargs)
Set the categories to the specified new_categories.
Series.cat.as_ordered(*args, **kwargs)
Set the Categorical to be ordered.
Series.cat.as_unordered(*args, **kwargs)
Set the Categorical to be unordered.

Sparse accessor

sparse-dtype(희소행렬) 관련 특정 메서드 및 속성은 Series.sparse 접근자를 통해 접근할 수 있다.

Series.sparse.npoints
The number of non- fill_value points.
Series.sparse.density
The percent of non- fill_value points, as decimal.
Series.sparse.fill_value
Elements in data that are fill_value are not stored.
Series.sparse.sp_values
An ndarray containing the non- fill_value values.
Series.sparse.from_coo(A[, dense_index])
Create a Series with sparse values from a scipy.sparse.coo_matrix.
Series.sparse.to_coo([row_levels, ...])
Create a scipy.sparse.coo_matrix from a Series with MultiIndex.

 

 

 

Comments