0
import csv
import pandas as pd


def fun(name='text.csv'):
   file = open(name, 'rb')
  _input = pd.read_csv(file, header=None)
  _output = pd.DataFrame()

   for index, i in _input.iterrows():
       main_series = i[:3]
       for j in range(0, 8):
         sub_series = (i[3 + 5 * j:8 + 5 * j])
         print((main_series.append(sub_series)).reset_index())
         #_output=_output.append((main_series.append(sub_series)).reset_index(),ignore_index=True)

    _output.to_csv('upadated_' + name)
    break
fun()

In this code When I'm appending subseries with main_series with reset_index I'm getting a dataframe. But how to get a Series instead?

index         0
0      0      A002
1      1      R051
2      2  02-00-00
3      3  04-30-11
4      4  00:00:00
5      5   REGULAR
6      6   3143506
7      7   1087907
  • Can you show the snippet of dataframe you are getting ? You can just select the column if you want series – Bharath M Shetty Oct 24 '17 at 12:28
  • Please add this in the question – Bharath M Shetty Oct 24 '17 at 12:34
  • Use `s = main_series[0]` to get the series simple – Bharath M Shetty Oct 24 '17 at 12:37
  • Working.! Great.! But Is this the efficient way? –  Oct 24 '17 at 12:39
  • Yes if you have the dataframe returned – Bharath M Shetty Oct 24 '17 at 12:43
  • If I don't reset index ill be returned with a series. Can we do something there? I want a series with the index reset and in efficient way –  Oct 24 '17 at 12:44
  • Tell me why do to want series in the first place – Bharath M Shetty Oct 24 '17 at 12:46
  • This Is an udacity assignment.In which we will have a input data set which will contain rows which should have been multiple rows individually. So my job is to convert those single rows into multiple rows and output a new file containing those new values. In an input row the first 3 values of that row will be common for all the new rows I have to create using that row. ie there are 42 columns . first ill extract that common 3 column values then iterate through the remaing columns extract four values(sub_series) and will concatenate them will do it for all the rows. –  Oct 24 '17 at 12:51
  • 1
    Possible duplicate of [Convert pandas data frame to series](https://stackoverflow.com/questions/33246771/convert-pandas-data-frame-to-series) – Nickpick Oct 24 '17 at 12:56

0 Answers0