我现在在练熊猫
我正在使用一些口袋妖怪数据作为实践
我想要做一个程序,允许用户输入他们的查询,我将返回他们需要的结果。
因为我不知道用户会输入多少参数,我只是做了一些代码,将其分解,然后放入熊猫能够理解的格式,但是当我试图执行我的代码时,它就是不返回。
我的密码怎么了?
谢谢
import pandas as pd
df = pd.read_csv(r'PATH HERE')
column_heads = df.columns
print(f'''
This is a basic searcher
Input your search query as
下面的代码如何过滤出pandas中的结果?例如,使用以下语句:
df[['name', 'id', 'group']][df.id.notnull()]
我得到了426行(它会过滤掉df.group IS NOT NULL所在的所有行)。但是,如果我只使用语法本身,它会为每一行返回一个bool,{index: bool}:
[df.group.notnull()]
括号表示法如何与pandas配合使用?另一个例子是:
df.id[df.id==458514] # filters out rows
# vs
[df.id==
我正在尝试使用类似于的布尔级数来索引数据帧
In [1]: import pandas as pd
In [2]: idx = pd.Index(["USD.CAD", "AUD.NZD", "EUR.USD", "GBP.USD"],
...: name="Currency Pair")
In [3]: pairs = pd.DataFrame({"mean":[3.6,5.1,3.6,2.7], "count":[1,5,8,2]}, inde
我使用了一个数据have (初始索引为0.9999),并按年份进行了分区:
requests_df = {year : df[df['req_year'] == year] for year in df['req_year'].unique()}
和往常一样,每个子帧保留自己的索引顺序。然后,在尝试对其中一个孤立帧(df_yr = requests_df[2015])进行索引时,我得到了一个非常出乎意料的行为:
for idx in df_year.index:
qty = frame[idx]['qty_tickets']
原因
a = [ [1,2,3,4,5], [6,np.nan,8,np.nan,10]]
df = pd.DataFrame(a, columns=['a', 'b', 'c', 'd', 'e'], index=['foo', 'bar'])
In [5]: df
Out[5]:
a b c d e
foo 1 2.0 3 4.0 5
bar 6 NaN 8 NaN 10
我理解普通的布尔索引是如何工作的,例如,如果我想选择具有c
import pandas as pd
grades = pd.Series({'Wally': 87, 'Eva': 100, 'Sam': 94},index=['a', 'b', 'c'])
print(grades)
产出:
a NaN
b NaN
c NaN
dtype: float64
为什么是这个输出?我在不同的站点中搜索,但是当在字典初始化器中使用index属性时,我不理解这个输出。请给我解释一下。
我有一个数据帧df,它看起来像这样: id Type agent_id created_at
0 44525 Stunning 6 bedroom villa in New Delhi 184 2018-03-09
1 44859 Villa for sale in Amritsar 182 2017-02-19
2 45465 House in Far
我想根据一个DataFrame检查从Pandas DataFrame中删除一个行子集。
初级DataFrame
>>> df
name day fruit foobar
0 Tim 1 Apple 0
1 Tim 1 Apple 1
2 Tim 2 Apple 2
3 Anna 1 Banana 3
4 Anna 1 Strawberry 4
5 Bob 1 Strawberry
这是我的数据集
import pandas as pd
df={'A':['1@1','2,3','3,4',5]}
df=pd.DataFrame(df1)
df
A
0 1@1
1 2,3
2 3,4
3 5
我想在有","的A列中找到数据索引
我试过这段代码,但它不起作用。
Index=[]
for i in df["A"]:
if ("," in i):
Index.append(df["A"][i].index)