pandas 将数据帧转换为多列的系列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52329220/
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 06:01:52  来源:igfitidea点击:

Convert dataframe to series for multiple column

pythonpandasdataframeseries

提问by saravanan saminathan

This is also a dataset contain 2 dimension but it is series typeConvert dat frame to series

这也是一个包含二维但它是系列类型的数据集将数据框转换为系列

I tried to convert the data frame to series But it shows the following error. I used pandas.Series(Dataframe) -> to convert Dataframe to series

我试图将数据框转换为系列但它显示以下错误。我使用 pandas.Series(Dataframe) -> 将 Dataframe 转换为系列

I want a output in the format of 1st image

我想要第一个图像格式的输出

采纳答案by yogkm

Please try the following approach to get a Series object from mentioned data(assuming datais the DataFrame you're using)

请尝试以下方法从提到的数据中获取 Series 对象(假设data是您正在使用的 DataFrame)

series = pd.Series(data['Sales'], index=data.index)

Hope that helps.

希望有帮助。

回答by Manmeet Singh

I would suggest you to see the answer by https://stackoverflow.com/a/33247007/3528612You should think of it as a problem of converting multiple column to a series. Hence as suggested in the answer by @dsm you should extract columns out of the dataframe.

我建议您通过https://stackoverflow.com/a/33247007/3528612查看答案 您应该将其视为将多列转换为系列的问题。因此,正如@dsm 在回答中所建议的那样,您应该从数据框中提取列。