1. concat two dataframes without losing the column headers

As stated in merge, join, and concat documentation, ignore index will remove all name references and use a range (0...n-1) instead. So it should give you the result you want once you remove ignore_index argument or set it to false (default).

df = pd.concat([df, df2], axis=1)

This will join your df and df2 based on indexes (same indexed rows will be concatenated, if other dataframe has no member of that index it will be concatenated as nan).

2. 重置 index


3. 重置 column name 为另一个 dataframe 的 column names

df1.columns = df2.columns[:].tolist()

4. 挑选行列

pick = [1,4,6,8]
df.ix[pick] # 挑选行

df.iloc[:, 0:150:5] # 前面代表选择所有列,后面代表选择从 0 到 150 行,每隔5个取一个

0 issues reported

results matching ""

    No results matching ""