草庐IT

dataframe

全部标签

python - 如何使用多索引移动 Pandas DataFrame?

使用以下DataFrame,如何在不让Pandas将移位后的值分配给不同的索引值的情况下根据索引移动“beyer”列?line_dateline_racebeyerhorseLastGunfighter2013-09-281099LastGunfighter2013-08-1810102LastGunfighter2013-07-068103.....Paynter2013-09-2810103Paynter2013-08-311088Paynter2013-07-278100df['beyer'].shift(1)产生...line_dateline_racebeyerbeyer_s

python - 向具有特定索引名称的 Pandas DataFrame 添加新行

我正在尝试向DataFrame添加一个具有特定索引名称'e'的新行。numbervariablevaluesaNaNbanktrueb3.0shopfalsec0.5markettruedNaNgovernmenttrue我尝试了以下方法,但它创建的是新列而不是新行。new_row=[1.0,'hotel','true']df=df.append(new_row)仍然不明白如何插入具有特定索引的行。将不胜感激任何建议。 最佳答案 您可以使用df.loc[_not_yet_existing_index_label_]=new_row。

python - 向具有特定索引名称的 Pandas DataFrame 添加新行

我正在尝试向DataFrame添加一个具有特定索引名称'e'的新行。numbervariablevaluesaNaNbanktrueb3.0shopfalsec0.5markettruedNaNgovernmenttrue我尝试了以下方法,但它创建的是新列而不是新行。new_row=[1.0,'hotel','true']df=df.append(new_row)仍然不明白如何插入具有特定索引的行。将不胜感激任何建议。 最佳答案 您可以使用df.loc[_not_yet_existing_index_label_]=new_row。

python - pandas groupby中的最大和最小日期

我有一个看起来像这样的数据框:data={'index':['2014-06-2210:46:00','2014-06-2419:52:00','2014-06-2517:02:00','2014-06-2517:55:00','2014-07-0211:36:00','2014-07-0612:40:00','2014-07-0512:46:00','2014-07-2715:12:00'],'type':['A','B','C','A','B','C','A','C'],'sum_col':[1,2,3,1,1,3,2,1]}df=pd.DataFrame(data,columns

python - pandas groupby中的最大和最小日期

我有一个看起来像这样的数据框:data={'index':['2014-06-2210:46:00','2014-06-2419:52:00','2014-06-2517:02:00','2014-06-2517:55:00','2014-07-0211:36:00','2014-07-0612:40:00','2014-07-0512:46:00','2014-07-2715:12:00'],'type':['A','B','C','A','B','C','A','C'],'sum_col':[1,2,3,1,1,3,2,1]}df=pd.DataFrame(data,columns

python - 从 ElasticSearch 结果创建 DataFrame

我正在尝试在pandas中构建一个DataFrame,使用对Elasticsearch进行非常基本的查询的结果。我得到了我需要的数据,但它需要对结果进行切片以构建正确的数据框。我真的只关心获取每个结果的时间戳和路径。我尝试了几种不同的es.search模式。代码:fromdatetimeimportdatetimefromelasticsearchimportElasticsearchfrompandasimportDataFrame,Seriesimportpandasaspdimportmatplotlib.pyplotaspltes=Elasticsearch(host="192

python - 从 ElasticSearch 结果创建 DataFrame

我正在尝试在pandas中构建一个DataFrame,使用对Elasticsearch进行非常基本的查询的结果。我得到了我需要的数据,但它需要对结果进行切片以构建正确的数据框。我真的只关心获取每个结果的时间戳和路径。我尝试了几种不同的es.search模式。代码:fromdatetimeimportdatetimefromelasticsearchimportElasticsearchfrompandasimportDataFrame,Seriesimportpandasaspdimportmatplotlib.pyplotaspltes=Elasticsearch(host="192

python - 比较 Python Pandas DataFrames 以匹配行

我在Pandas中有这个DataFrame(df1):df1=pd.DataFrame(np.random.rand(10,4),columns=list('ABCD'))printdf1ABCD0.8603790.7269560.3945290.8332170.0141800.8138280.5598910.3396470.7828380.6989930.5512520.3610340.8333700.9820560.7418210.0068640.8559550.5465620.2704250.1360060.4915380.4450240.9716030.6900010.9116

python - 比较 Python Pandas DataFrames 以匹配行

我在Pandas中有这个DataFrame(df1):df1=pd.DataFrame(np.random.rand(10,4),columns=list('ABCD'))printdf1ABCD0.8603790.7269560.3945290.8332170.0141800.8138280.5598910.3396470.7828380.6989930.5512520.3610340.8333700.9820560.7418210.0068640.8559550.5465620.2704250.1360060.4915380.4450240.9716030.6900010.9116

python - 在两个 Numpy 数组之间创建 Pandas Dataframe,然后绘制散点图

我对numpy和pandas比较陌生(我是一名实验物理学家,所以多年来我一直在使用ROOT……)。ROOT中的一个常见图是2D散点图,其中给定x和y值列表,生成一个变量与另一个变量的“热图”类型散点图。如何用numpy和Pandas最好地完成这项工作?我正在尝试使用Dataframe.plot()函数,但我什至难以创建Dataframe。importnumpyasnpimportpandasaspdx=np.random.randn(1,5)y=np.sin(x)df=pd.DataFrame(d)首先,这个数据框的形状为(1,2),但我希望它的形状为(5,2)。如果我能得到正确的数据