重命名 pandas.concat 的 DataFrame 输出上的列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41103800/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Renaming columns on DataFrame output of pandas.concat
提问by Thomas Murphy
I'm construction a new DataFrame by concatenating the columns of other DataFrames, like so:
我正在通过连接其他 DataFrame 的列来构建一个新的 DataFrame,如下所示:
pairs = pd.concat([pos1['Close'], pos2['Close'], pos3['Close'], pos4['Close'], pos5['Close'],
pos6['Close'], pos7['Close']], axis=1)
I want to rename all of the columns of the pairs
Dataframe to the symbol of the underlying securities. Is there a way to do this during the the concat method call? Reading through the docs on the method here http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.concat.htmldidn't give me a solid answer.
我想将pairs
Dataframe 的所有列重命名为基础证券的符号。在 concat 方法调用期间有没有办法做到这一点?通读这里方法的文档http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.concat.html并没有给我一个可靠的答案。
回答by Thomas Murphy
This is the approach I'm taking. Seems to fit all my requirements.
这是我正在采取的方法。似乎符合我的所有要求。
symbols = ['JPM', 'WFC', 'BAC', 'C', 'STI', 'PNC', 'CMA']
pairs.columns = symbols