使用 Pandas 中的系列连接 DataFrame
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35830833/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:49:29 来源:igfitidea点击:
concat a DataFrame with a Series in Pandas
提问by cacert
采纳答案by bakkal
You want to use this form:
你想使用这个表格:
result = pd.concat([dataframe, series], axis=1)
The pd.concat(...)
doesn't happen "inplace" into the original dataframe
but it would returnthe concatenated result so you'll want to assign the concatenation somewhere, e.g.:
该pd.concat(...)
不会发生“就地”成原来的dataframe
,但它会返回连接的结果,所以你要分配的级联的地方,如:
>>> import pandas as pd
>>> s = pd.Series([1,2,3])
>>> df = pd.DataFrame()
>>> df = pd.concat([df, s], axis=1) # We assign the result back into df
>>> df
0
0 1
1 2
2 3