我们必须按给定的列名(列名列表)对其进行分组。之后,应打印具有指定列值(值)的组的数据。输入将包含两行。第一行将有一个列列表,第二行将有一个值列表.输出应该有对应组的前五行。
我需要使用print命令打印dataframe。
样本输入:
['Pclass','Age']
[3,13]
产出:
PassengerId Pclass Name Sex Age
154 1046 3 Asplund, Master. Filip Oscar male 13.0
我有这样的数据:
name . profession
Alex . Data Analyst
Markus . Sales Manager
Carlos . Credit Analyst
Otavio . HR Manager
...
我需要知道在这个dataframe中有多少人在它的职业中有字符串“分析师”。答案应该是2。
我正在尝试使用groupby和get_group,但是我没有找到正确的方法将其应用到get_group语法中。
现在我在这里:
df.groupby('profession').get_group(???).agg('count')
我刚刚开始学习熊猫。我正在做一个视频游戏销售数据的项目。我正在处理的数据框如下所示:
Rank Name Platform Year Genre Publisher Global_Sales
0 1 Wii Sports Wii 2006.0 Sports Nintendo 41.49
1 2 Super Mario Bros. NES 1985.0 Platform Nintendo 29.08
2 3 Ma
我想使用值s来创建n个DataFrames,作为每个DataFrame的名称,但是我只能创建一个充满DataFrames的列表。是否可以在其中的每个DataFrames中更改此列表?
#estacao has something like [ABc,dfg,hil,...,xyz], and this should be the name of each DataFrame
estacao = dados.Station.unique()
for s,i in zip(estacao,range(126)):
estacao[i] = dados.groupby('
我试着用熊猫对一些信息数据做一些分析,并且遇到一些问题,试着准备这些数据。它来自一个我无法控制的数据库,因此在分析它之前,我需要做一些修剪和格式化。
这就是我目前所处的位置:
#select all the messages in the database. Be careful if you get the whole test data base, may have 5000000 messages.
full_set_data = pd.read_sql("Select * from message",con=engine)
在对时间戳进行此更改并将其设置为索引之后,就不
我得到了一个分组的DataFrame df,我正在寻找一个类似于get_group( KeyError )的函数,除了在名称不存在时抛出一个DataFrame,返回一个空的DataFrame(或其他值),类似于dict.get的工作方式:
g = df.groupby('x')
# doesn't work, but would be nice:
i = g.get_group(1, default=[])
# does work, but is hard to read:
i = g.obj.take(g.indices.get(1, []), g.axis)
是
我有一只像这样的熊猫DataFrame:
test = pd.DataFrame({'score1' : pandas.Series(['a', 'b', 'c', 'd', 'e']), 'score2' : pandas.Series(['b', 'a', 'k', 'n', 'c'])})
输出:
score1 score2
0 a b
1 b a
2 c
我的数据看起来像,
A B
1 2
1 3
1 4
2 5
2 6
3 7
3 8
如果我是df.groupby('A'),如何将每个组转换为子数据格式(Sub),因此对于A=1,它将是这样的。
A B
1 2
1 3
1 4
对于A=2,
A B
2 5
2 6
对于A=3,
A B
3 7
3 8
我在逐个学期记录等级直方图。
我想做一个互动的Bokeh条形图与滑块,可以循环通过条款。
我有条形图工作在一个单一的条款,但当我试图添加额外的条件,我不能让条形图选择一个单一的项目,然后进行更新和轻微地通过它。
我真的需要一些帮助,让groupby对象只选择一个术语。
import os
from bokeh.plotting import figure, ColumnDataSource
from bokeh.io import curdoc, output_file, show
from bokeh.layouts import widgetbox
from bokeh.models im
import pandas as pd
tweets = pd.read_csv("file_name")
# Group the data by hashtag to extract books with the hashtag RoeVWade only
roevwade = tweets.groupby("hashtags").get_group("['RoeVWade']")
# Print the date of the first tweet with only the RoeVWade hashtag
prin
我试图对groupby对象中的每个组应用一个自定义函数,并将结果存储到每个组本身的新列中。函数返回两个值,我希望将这些值分别存储到每个组中的两个列中。
我试过这样做:
# Returns True if all values in Column1 is different.
def is_unique(x):
status = True
if len(x) > 1:
a = x.to_numpy()
if (a[0] == a).all():
status = False
return status
#
我有一个DataFrame,其中多个列包含相同的数据,存储方式不同。
例如,一列中充满了运营商名称(美国航空公司的AA等),而另一列则充满了承运人ID。
如何快速检查这两列是否实际填充了相同的信息(每个运营商确实只有一个ID ?)目标是安全丢弃两列中的一列?
到目前为止,我得到了以下信息:
#for each carrier
for carrier in data.CARRIER.unique():
#print all the different AIRLINE_ID that appear when we subset the data for this carrier
p
# Selecting all of the Subscriber & Children Tier People
D = df[df['Member Tier'].str[0] == 'D']
CountD =D[D['Relation'].str[0] == 'M']
= len(CountD) 我有一个根据成员层和关系对人员进行分类的数据集,有什么方法可以将这些步骤合并为一个步骤?
我试图通过一个函数将df元组的pandas列表转换为独立DataFrames的len编号。我发现了一个简单的样本DataFrame,它由不同的动物类型组成。我不想创建一个元组格式的DataFrames列表,而是希望将它们推到单独的DataFrames表(不是元组等)中,而不是逐个调用df的位置(即animals[0]),因为我不知道任何给定的列表会有多长。有什么建议吗? import pandas as pd
df = pd.DataFrame({'animal': 'cat dog cat fish dog cat cat'.split(),
's