【发布时间】:2020-11-08 05:34:32
【问题描述】:
背景:
我有一个 DataFrame ('weather_tweets'),其中包含两列感兴趣的列,weather(火星上的天气)和 date(日期天气有关)。结构如下:
目标:
我正在尝试编写代码来确定最新的日期戳(date 列)并打印该行对应的 weather 列值。
示例行:
这是示例行:
weather_tweets = [
('tweet', 'weather', 'date'),
('Mars Weather@MarsWxReport·Jul 15InSight sol 58', 'InSight sol 580 (2020-07-14) low -88.8ºC (-127.8ºF) high -8.4ºC (16.8ºF) winds from the WNW at 5.9 m/s (13.3 mph) gusting to 15.4 m/s (34.4 mph) pressure at 7.80 hPa, '2020-07-14')]
我的代码:
到目前为止,我只能编写一些乱七八糟的代码来按顺序返回最新日期,但这对我的预期结果毫无用处:latest_weather = weather_tweets.groupby(['tweet', 'weather'])['date'].transform(max) == weather_tweets['date']print(weather_tweets[latest_weather])
任何关于如何达到预期结果的建议将不胜感激。
【问题讨论】:
-
所以您只想打印 1 行,其中包含整个数据框中的最新日期?
-
你能分享一些文本格式的示例行吗?
-
@MabelVillalba - 当然,我已经添加了一个示例行。
-
@ipj - 正确,但是我只需要打印该行的“天气”列值的内容
标签: python pandas dataframe jupyter-lab datestamp