擅长:python、mysql、java
<pre><code>import pandas as pd
sample_dict = {'Date':['2010-01-11', '2020-01-22', '2010-03-12'], 'Price':[1000,2000,3500]}
df = pd.DataFrame(sample_dict)
# Creating 'year' column using the Date column
df['year'] = df.apply(lambda row: row.Date.split('-')[0], axis=1)
# Groupby function
df1 = df.groupby('Year')
# Print the first value in each group
df1.first()
</code></pre>
<p>输出:</p>
<pre><code> Date x
year
2010 2010-01-11 1
2020 2020-01-22 2
</code></pre>