现在,当我的时间序列在十年之初(即 1990、2000、2010 年等)开始时,我有一些符合我的规范的工作代码,但我不知道如何调整我的代码以具有当我的时间序列从不是偶数的年份(即 1993 年)开始时的正确格式。
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import dates
def format_xaxis(fig):
years = dates.YearLocator(10,month=1,day=1)
years1=dates.YearLocator(2,month=1,day=1)
dfmt = dates.DateFormatter('%Y')
dfmt1 = dates.DateFormatter('%y')
[i.xaxis.set_major_locator(years) for i in fig.axes]
[i.xaxis.set_minor_locator(years1) for i in fig.axes]
[i.xaxis.set_major_formatter(dfmt) for i in fig.axes]
[i.xaxis.set_minor_formatter(dfmt1) for i in fig.axes]
[i.get_xaxis().set_tick_params(which='major', pad=15) for i in fig.axes]
for t in fig.axes:
for tick in t.xaxis.get_major_ticks():
tick.label1.set_horizontalalignment('center')
for label in t.get_xmajorticklabels() :
label.set_rotation(0)
label.set_weight('bold')
for label in t.xaxis.get_minorticklabels():
label.set_fontsize('small')
for label in t.xaxis.get_minorticklabels()[::5]: …Run Code Online (Sandbox Code Playgroud) 该问题基于SQL 查询来选择具有最小值的不同行。考虑下表:
id game point
1 x 1
1 y 10
1 z 1
2 x 2
2 y 5
2 z 8
Run Code Online (Sandbox Code Playgroud)
使用上述问题的建议答案(选择点列中具有最小值的 id,按游戏分组),我们获得
id game point
1 x 1
1 z 1
2 x 2
Run Code Online (Sandbox Code Playgroud)
问题是如何通过每个 ID 的单个输出获得答案。两个输出
id game point
1 x 1
2 x 2
Run Code Online (Sandbox Code Playgroud)
和
id game point
1 z 1
2 x 2
Run Code Online (Sandbox Code Playgroud)
是可以接受的。