Dask .loc 只有第一个结果 (iloc[0])
Dask .loc only the first result (iloc[0])
样本数据帧:
import pandas as pd
import dask
import dask.dataframe as dd
df = pd.DataFrame({'col_1': [1,2,3,4,5,6,7], 'col_2': list('abcdefg')},
index=pd.Index([0,0,1,2,3,4,5]))
df = dd.from_pandas(df, npartitions=2)
现在我只想得到第一个(基于索引)结果 - 就像 pandas 中的这样:
df.loc[df.col_1 >3].iloc[0]
col_1 col_2
2 4 d
I know there is no positional row indexing in dask using iloc
,但我想知道是否可以 将查询限制为 1 个结果,如 SQL?
知道了 - 但不确定这里的效率:
tmp = df.loc[df.col_1 >3]
tmp.loc[tmp.index == tmp.index.min().compute()].compute()
样本数据帧:
import pandas as pd
import dask
import dask.dataframe as dd
df = pd.DataFrame({'col_1': [1,2,3,4,5,6,7], 'col_2': list('abcdefg')},
index=pd.Index([0,0,1,2,3,4,5]))
df = dd.from_pandas(df, npartitions=2)
现在我只想得到第一个(基于索引)结果 - 就像 pandas 中的这样:
df.loc[df.col_1 >3].iloc[0]
col_1 col_2
2 4 d
I know there is no positional row indexing in dask using iloc
,但我想知道是否可以 将查询限制为 1 个结果,如 SQL?
知道了 - 但不确定这里的效率:
tmp = df.loc[df.col_1 >3]
tmp.loc[tmp.index == tmp.index.min().compute()].compute()