3

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

I want a output in the format of 1st image

  • 1
    Series is a one-dimensional object while DataFrame is multi-dimentional object. What you're trying to do is assigning multiple columns as a Series. – yogkm Sep 14 '18 at 09:52
  • series = read_csv('shampoo-sales.csv', header=0, parse_dates=[0], index_col=0, squeeze=True, date_parser=parser). If I read the file in this format i got series type with 2 dimension.(1st image in the question) – saravanan saminathan Sep 14 '18 at 12:42
  • I would suggest you to see the answer by https://stackoverflow.com/a/33247007/3528612 You 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. – Manmeet Singh Sep 14 '18 at 09:48

1 Answers1

10

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

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

Hope that helps.

yogkm
  • 649
  • 5
  • 15
  • 1
    Shouldn't it rather be series = pd.Series(data['Sales'], index=data.Month) if he wants to index by the Month column? I have similar problem however when I use this approach I get NaN for my Sales like column. – Sameer Mahajan Oct 21 '21 at 15:30