1. Pandas中,如果用字典构造系列和数据帧,如果强行指定index或者column,则以强行指定的为准,指定的index或者column中没有,但是字典本身有的数据将被忽略,指定的index或者column中有,但是字典本身没有的数据将被置NaN
2. DataFrame的某一列为Series,则DataFrame的index必须和Series的index一样,不然所有数据都将是NaN,因此使用这种方式的时候,最好的方法就是数据帧构建过程中不设置index,而是在每一个Series构建的时候构造相同的index,如下
# !user/bin/python
# -*- coding: UTF-8 -*-
import numpy as np
import pandas as pd
# 数据帧的选择
dic = {'col1' : pd.Series(np.arange(4),index = ['one', 'two', 'three', 'four']),
'col2' : pd.Series(np.arange(100, 100 + 4), index = ['one', 'two', 'three', 'four'])}
df = pd.DataFrame(dic)
print(df)
# col1 col2
# one 0 100
# two 1 101
# three 2 102
# four 3 103
3. permutation和shuffle
permutation传入一个int或者一个ndarray,shuffle只能传入一个ndarray
permutation有返回值,不改变原有arr,shuffle没有返回值,会改变原有arr
permutation速度比shuffle慢
import numpy as np
a