[英]python - Find first occurence in Time series
I have a large dataframe with observations repeated each month.我有一个大型数据框,每个月都会重复观察。
I want to extract the first apparition of each observations.我想提取每个观察的第一个幻影。
For instance, consider the following dataset :例如,考虑以下数据集:
Name date value
A. June 2020. 15
A. July 2020. 20
A. August 2020. 10
B. July 2020. 30
B. August 2020. 40
C. August 2020. 5
I want to obtain :我想获得:
Name date value
A. June 2020. 15
B. July 2020. 30
C. August 2020. 5
Lead function in SQL would be suitable. SQL 中的 Lead 函数将是合适的。 So you might be use sqlite or pandas in python.所以你可能会在 python 中使用 sqlite 或 pandas。 By using pandas, you could search "pandas lead" in google or stack, like this Pandas equivalent of Oracle Lead/Lag function .通过使用 pandas,您可以在 google 或 stack 中搜索“pandas Lead”,就像这个Pandas 等效于 Oracle Lead/Lag function 。
你可以试试drop_duplicates
df.drop_duplicates(subset=['Name'], keep='first', inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.