目录
  • pandas入门
    • pandas语法
    • pandas处理日期

 

pandas入门

pandas语法

  1. DataFrame类
# 注:[]表示里面是传入参数
# 属性
DataFrame.index	# 取序列号
DataFrame.columns	# 取表的字段
DataFrame.info([...])	# 表的统计总结
DataFrame.values	# 返回Numpy格式
# Indexing, iteration
DataFrame.head([n])	# 返回前n行数据
DataFrame.loc
DataFrame.iloc
DataFrame.insert([loc, column, value[,...]])
DataFrame.items()
DataFrame.where()
DataFrame.query()
# Function applicatoin, GroupBy & window
DataFrame.apply(func[,axis=0,raw,...])	# apply a function along an axis of the DataFrame. 逐行或者逐列处理
DataFrame.applymap(func[,na_action])	# apply a function to a DataFrame elementwise. 逐个应用
DataFrame.aggregate([func, axis])	# aggregate using one or more operations over the specified axis.
DataFrame.groupby([by, axis, level, ...])	# Group DataFrame using a mapper or by a Series of columns.
  1. 删除行
df = df.drop([<row>.index])
  1. 选择
df[df['name'].isin(['Jonh', 'Lucy'])]
  1. 排序
df.sort_values(by=['data_date'])
  1. 创建空的Dataframe,逐行添加数据
df = pd.DataFrame(columns=['a', 'b'])
df = df.append(your_data, ignore_index=True)	# 要注意忽略索引
  1. 硬编码和one-hot编码

pandas处理日期

# 取星期几
d=datetime.datetime.now()
d.weekday()
每天进步一点点! ©版权声明 文章版权归作者所有,未经允许请勿转载。