<p>您可以通过执行开始的concat并将其扩展到另一个轴来实现这一点。通过从这些系列创建两个数据帧,可以将它们重新合并在一起并创建所需的索引:</p>
<pre><code>blib = states.iloc[0]
blub = states.iloc[1]
times_df = pd.DataFrame(pd.concat([blib, blub]), columns=['value'])
times_df.reset_index(inplace=True)
# Renaming index so that there aren't two 'index' columns after merge
times_df.rename(columns={'index': 'time'}, inplace=True)
a = states['00:00']
b = states['01:00']
dates_df = pd.DataFrame(pd.concat([a, b]), columns=['value'])
dates_df.reset_index(inplace=True)
dates_df.rename(columns={'index': 'date'}, inplace=True)
# Merging gives the four rows you want but still need to create index
merged = pd.merge(times_df, dates_df, on='value')
merged['datetime'] = pd.to_datetime(merged['date'] + ' ' + merged['time'])
merged.drop(['date', 'time'], axis=1, inplace=True)
merged.set_index('datetime', drop=True, inplace=True)
result = merged['value']
</code></pre>
<p>结果输出:</p>
^{pr2}$
<p>如果您希望将索引作为字符串,请将<code>merged['datetime'] = ...</code>行改为:</p>
<pre><code>merged['datetime'] = merged['date'] + ' ' + merged['time']
</code></pre>
<p>结果将完全符合您的要求:</p>
<pre><code>datetime
2007-01-01 00:00 1
2007-01-01 01:00 2
2007-01-02 00:00 4
2007-01-02 01:00 5
Name: value, dtype: int64
</code></pre>
<p>编辑:我意识到这不是很有效,多索引方法可能更有前途。在</p>