Buscar

DataFrame resample()

Prévia do material em texto

Funções dos Pandas Python (/pt/api/python-pandas/)
Pandas DataFrame DataFrame.shift() Função (/pt/api/python-pandas/pandas-dataframe-dataframe.shift-function/)
Pandas DataFrame DataFrame.query() Função (/pt/api/python-pandas/pandas-dataframe-dataframe.query-function/)
Pandas DataFrame DataFrame.interpolate() Função (/pt/api/python-pandas/pandas-dataframe-dataframe.interpolate-function/)
Pandas DataFrame DataFrame.aggregate() Função (/pt/api/python-pandas/pandas_dataframe_dataframe.aggregate_function/)
Pandas DataFrame DataFrame.dropna() Função (/pt/api/python-pandas/pandas-dataframe-dataframe.dropna-function/)
 (/pt) > Api (/pt/api/) > Funções dos Pandas Python (/pt/api/python-pandas/)
> Função Pandas DataFrame.resample() (/pt/api/python-pandas/pandas-dataframe-dataframe.resample-function/)
Função Pandas DataFrame.resample()
Pandas (/pt/tags/pandas/) Pandas DataFrame (/pt/tags/pandas-dataframe/)
Criado: March-30, 2021 | Atualizado: June-22, 2021
 (http://www.facebook.com/sharer.php?src=bm&u=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpython-
pandas%2fpandas-dataframe-dataframe.resample-
function%2f&t=Fun%c3%a7%c3%a3o%20Pandas%20DataFrame.resample%28%29) (https://twitter.com/intent/tweet/?
text=Fun%c3%a7%c3%b5es%20dos%20Pandas%20Python -
Fun%c3%a7%c3%a3o%20Pandas%20DataFrame.resample%28%29&url=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpy
pandas%2fpandas-dataframe-dataframe.resample-function%2f&hashtags=web,development)
(https://www.linkedin.com/shareArticle?mini=true&url=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpython-
pandas%2fpandas-dataframe-dataframe.resample-function%2f&title=Fun%c3%a7%c3%b5es%20dos%20Pandas%20Python -
Fun%c3%a7%c3%a3o%20Pandas%20DataFrame.resample%28%29&source=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2
pandas%2fpandas-dataframe-dataframe.resample-function%2f&summary=Short%20summary)
A função Python Pandas DataFrame.resample() (https://pandas.pydata.org/pandas-
docs/stable/reference/api/pandas.DataFrame.resample.html) faz uma nova amostra dos dados da série temporal.
1. Sintaxe de pandas.DataFrame.resample() :
2. Códigos de exemplo: Método DataFrame.resample() para reamostrar os dados da série semanalmente
3. Códigos de exemplo: Método DataFrame.resample() para reamostrar os dados da série com base mensal
TABELA DE CONTEÚDO
Sintaxe de pandas.DataFrame.resample() :
https://www.delftstack.com/pt/api/python-pandas/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.shift-function/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.query-function/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.interpolate-function/
https://www.delftstack.com/pt/api/python-pandas/pandas_dataframe_dataframe.aggregate_function/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.dropna-function/
https://www.delftstack.com/pt
https://www.delftstack.com/pt/api/
https://www.delftstack.com/pt/api/python-pandas/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.resample-function/
https://www.delftstack.com/pt/tags/pandas/
https://www.delftstack.com/pt/tags/pandas-dataframe/
http://www.facebook.com/sharer.php?src=bm&u=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpython-pandas%2fpandas-dataframe-dataframe.resample-function%2f&t=Fun%c3%a7%c3%a3o%20Pandas%20DataFrame.resample%28%29
https://twitter.com/intent/tweet/?text=Fun%c3%a7%c3%b5es%20dos%20Pandas%20Python%20-%20Fun%c3%a7%c3%a3o%20Pandas%20DataFrame.resample%28%29&url=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpython-pandas%2fpandas-dataframe-dataframe.resample-function%2f&hashtags=web,development
https://www.linkedin.com/shareArticle?mini=true&url=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpython-pandas%2fpandas-dataframe-dataframe.resample-function%2f&title=Fun%c3%a7%c3%b5es%20dos%20Pandas%20Python%20-%20Fun%c3%a7%c3%a3o%20Pandas%20DataFrame.resample%28%29&source=https%3a%2f%2fwww.delftstack.com%2fpt%2fapi%2fpython-pandas%2fpandas-dataframe-dataframe.resample-function%2f&summary=Short%20summary
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.resample.html
Parâmetros
rule É a string de deslocamento ou objeto que representa a conversão de destino.
axis Ele especi�ca qual eixo usar para aumentar ou diminuir a amostragem. Para Series, o padrão é 0, o que signi�ca ao
longo das linhas.
closed Ele especi�ca qual lado do intervalo bin está fechado. Tem duas opções: right ou left .
label Ele especi�ca o rótulo da borda da caixa para rotular o balde. Tem duas opções: right ou left .
convention Possui quatro opções: start , end , s , ou e . Apenas para PeriodIndex, ele usa o start ou end da regra.
kind Ele especi�ca o tipo de índice resultante. Possui duas opções: timestamp ou period . Timestamp converte o índice
resultante em DateTimeIndex e period o converte em PeriodIndex.
loffset Ele ajusta os rótulos de tempo reamostrados.
base É um número inteiro. Seu valor padrão é 0.
on Ele representa o nome da coluna a ser usada em vez do índice para reamostragem. A coluna deve ser semelhante a
data e hora.
level Ele representa o nome do nível a ser usado para reamostragem. O nível deve ser semelhante a data e hora.
origin É o carimbo de data/hora para ajustar o agrupamento. Tem três opções: epoch , start ou start_day .
offset Ele representa um deslocamento timedelta adicionado ao parâmetro origin .
Retornar
Ele retorna o objeto reamostrado.
Resultado:
DataFrame.resample(rule, 
 axis=0, 
 closed=None, 
 label=None, 
 convention='start', 
 kind=None, 
 loffset=None, 
 base=None, 
 on=None, 
 level=None, 
 origin='start_day', 
 offset=None) 


Códigos de exemplo: Método DataFrame.resample() para
reamostrar os dados da série semanalmente

import pandas as pd 
index = pd.date_range('1/1/2021', periods=30, freq='D') 
series = pd.Series(range(30), index=index) 
print("The Original Series is: \n") 
print(series) 
series1= series.resample('W').sum() 
print("The Resampled Data is: \n") 
print(series1) 
A função retornou a soma reamostrada semanalmente.
Resultado:
The Original Series is: 
2021-01-01 0 
2021-01-02 1 
2021-01-03 2 
2021-01-04 3 
2021-01-05 4 
2021-01-06 5 
2021-01-07 6 
2021-01-08 7 
2021-01-09 8 
2021-01-10 9 
2021-01-11 10 
2021-01-12 11 
2021-01-13 12 
2021-01-14 13 
2021-01-15 14 
2021-01-16 15 
2021-01-17 16 
2021-01-18 17 
2021-01-19 18 
2021-01-20 19 
2021-01-21 20 
2021-01-22 21 
2021-01-23 22 
2021-01-24 23 
2021-01-25 24 
2021-01-26 25 
2021-01-27 26 
2021-01-28 27 
2021-01-29 28 
2021-01-30 29 
Freq: D, dtype: int64 
The Resampled Data is: 
2021-01-03 3 
2021-01-10 42 
2021-01-17 91 
2021-01-24 140 
2021-01-31 159 
Freq: W-SUN, dtype: int64 
Códigos de exemplo: Método DataFrame.resample() para
reamostrar os dados da série com base mensal

import pandas as pd 
index = pd.date_range('1/1/2021', periods=30, freq='D') 
series = pd.Series(range(30), index=index) 
print("The Original Series is: \n") 
print(series) 
series1= series.resample('M').sum() 
print("The Resampled Data is: \n") 
print(series1) 
A função retornou a soma reamostrada mensalmente.
Pandas DataFrame DataFrame.groupby() Função (/pt/api/python-pandas/pandas-dataframe-dataframe.groupby-function/)
Pandas DataFrame DataFrame.drop_duplicates() Função (/pt/api/python-pandas/pandas-dataframe.drop_duplicates-function/)
 Função Pandas DataFrame.Insert() (/Pt/Api/Python-Pandas/Pandas-Dataframe-Dataframe.Insert-Function/)
 Função Pandas DataFrame.Reset_index()
The Original Series is: 
2021-01-01 0 
2021-01-02 1 
2021-01-03 2 
2021-01-04 3 
2021-01-05 4 
2021-01-06 5 
2021-01-07 6 
2021-01-08 7 
2021-01-098 
2021-01-10 9 
2021-01-11 10 
2021-01-12 11 
2021-01-13 12 
2021-01-14 13 
2021-01-15 14 
2021-01-16 15 
2021-01-17 16 
2021-01-18 17 
2021-01-19 18 
2021-01-20 19 
2021-01-21 20 
2021-01-22 21 
2021-01-23 22 
2021-01-24 23 
2021-01-25 24 
2021-01-26 25 
2021-01-27 26 
2021-01-28 27 
2021-01-29 28 
2021-01-30 29 
Freq: D, dtype: int64 
The Resampled Data is: 
2021-01-31 435 
Freq: M, dtype: int64 
Artigo relacionado - Pandas DataFrame
(/pt/tags/pandas-dataframe/)

Copyright © 2020. All right reserved
Sobre nós (/pt/about-us/) Política de Privacidade (/pt/privacy-policy/) Sitemap (/pt/sitemap/) Contato (/pt/contact/)
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.groupby-function/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe.drop_duplicates-function/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.insert-function/
https://www.delftstack.com/pt/api/python-pandas/pandas-dataframe-dataframe.reset_index-function/
https://www.delftstack.com/pt/tags/pandas-dataframe/
https://www.delftstack.com/pt/about-us/
https://www.delftstack.com/pt/privacy-policy/
https://www.delftstack.com/pt/sitemap/
https://www.delftstack.com/pt/contact/

Continue navegando

Outros materiais