Python 3.x 如何使用第一行和最后一行python提取数据帧的一部分
我正在从另一个数据帧创建一个新的数据帧。 我有第一行和最后一行,每一行都有不同的变量。提取这些行以创建新的数据帧需要什么Python 3.x 如何使用第一行和最后一行python提取数据帧的一部分,python-3.x,pandas,Python 3.x,Pandas,我正在从另一个数据帧创建一个新的数据帧。 我有第一行和最后一行,每一行都有不同的变量。提取这些行以创建新的数据帧需要什么 我已经检查了变量是否正确,但是当我创建新的DataFrame并使用.descripe()时,DataFrame是空的 我尝试替换实际日期的变量,在这种情况下,其中一个统计数据是错误的,因为第一个的输出是错误的 初试 输出 第二次尝试 输出 我期望第一个日期的输出是'2005-04-16 22:20:36',但实际输出是'2013-10-02 14:56:14'。新数据帧中的第
我期望第一个日期的输出是
'2005-04-16 22:20:36'
,但实际输出是'2013-10-02 14:56:14'
。新数据帧中的第一行似乎是错误的。它必须是git\u log.loc[first\u commit\u timestamp:last\u commit\u timestamp,:]
(即不带引号)而不是git\u log.loc['first\u commit\u timestamp':]
您还必须检查您的数据类型:现在看起来您的时间戳列是str
类型,但您可能希望有一个datetime类型列(请参阅转换)刚刚测试了“first\u commit\u timestamp”和“last\u commit\u timestamp”的数据类型,这就是答案。一定有什么明显的。。。谢谢您的帮助。@Stef我也尝试了不带引号的git_log.loc['first_commit_timestamp':'last_commit_timestamp',:],但出现的是:KeyError:timestamp('2005-04-16 22:20:36'))
corrected_log = git_log.loc['first_commit_timestamp':'last_commit_timestamp', : ]
print(corrected_log.describe())
timestamp author
count 0 0
unique 0 0
corrected_log = git_log.loc['2005-04-16 22:20:36':'2019-04-05 05:07:45', : ]
timestamp author
count 1400 1400
unique 1357 393
top 2014-12-11 23:56:04 Benjamin Romer
freq 15 46
first 2013-10-02 14:56:14 NaN
last 2015-08-01 10:03:00 NaN