1.从字典创建DataFrame 报错if using all scalar values,you must pass an index
my_dict ={1:'zhangsan',2:'lisi',3:'wangwu'}
pd.DataFrame.from_dict(my_dict)
应加入
pd.DataFrame.from_dict(my_dict,orient='index')
2.向DataFrame中横向插入一行list
如果直接插入会按列插入,因为
[1,2,3,4,5].shape = (5,)
必须转成1行5列
np.array([1,2,3,4,5]).reshape(1,-1)
[[1,2,3,4,5]].shape = (1,5)
3.对Series使用apply函数实现传参
先看看python的原生函数,如何进行多参数操作
# 提供了两个列表,对相同位置的列表数据进行相加
>>> map(lambda x, y: x + y, [1, 3, 5, 7, 9], [2, 4, 6, 8, 10])
series
London 20
New York 21
Helsinki 12
dtype: int64
def subtract_custom_value(x, custom_value):
return x-custom_value
series.apply(subtract_custom_value