程序员

pandas DataFrame数据筛选和切片

2020-07-02  本文已影响0人  Heshinia

源代码参考https://www.cnblogs.com/aro7/p/9748202.html

数据来源: 阿里巴巴国际站引流关键词

#查看表格前5行
import pandas as pd
inflow = pd.read_csv("文件名.csv")
inflow.head(5)
#筛选出有点击的关键词
inflow_click = inflow[ inflow['点击率'] >0]
inflow_click.head(5)
inflow2 = inflow['词'] [inflow['点击量'] >0]
inflow2.head(5)

isin函数

inflow3 = inflow[inflow['点击量'].isin([1, 2, 3])]
inflow3

运算符 & | ~

inflow4 = inflow[ (inflow["点击量"]>0) & (inflow['外贸直通车点击'] !=0) ]
inflow4

整行 整列切片

#前闭后开区间
inflow[10:15]
inflow[['词', '点击量']]

loc函数

inflow4.loc[753, ['点击量', '外贸直通车点击']]

iloc函数

inflow4.iloc[4, [0, 4]]

ix函数

inflow4.ix[4:9, ['词', '点击量']]

at函数

inflow4.at[5, '点击率']

iat函数

inflow4.iat[5, 0]
上一篇下一篇

猜你喜欢

热点阅读