python - Manipulating data from csv using pandas -


There is a question about the data of pandals, what I am looking for to bring two columns from the CSV file, and Manipulate data before saving in the end.

The CSV file looks like this:

  Year Month 2007 1 2007 2 2007 3 2007 4 2008 1 2008 3   

This My current code is:

  record = pd.read_csv (path) frame = pd.DataFrame (record) composite = datetime (frame ['year']. Unstable, frame [' Month ']. Unstable, 1)   

is an error:

  typeError: the series is "& lt; type' int '& gt;   

Any ideas?

Daytime work on one Will not panda series (column of dataframe) you to_datetim E or you can use datetime within applicable . You should do something like the following:

  in [9]: DF out [9]: year months 2007 1 1 2007 2 2 2007 3 3 2007 4 4 2008 1 5 2008 3 in [10]: PDto_datetime (DF ['sal'] Ashstop (SR) + '-' + DF ['month']. Volatile (SR) + '-1') Out [10]: 0 2007-01- 01 1 2007-02-01 2 2007-03-01 3 2007-04-01 4 2008-01-01 5 2008-03-01 dtype: datetime64 [ns]   

or use [11]: df.apply (Lambda X: Dataim (X ['' '', x ['month'], 1), axis = 1) [11]: 0 20 07-01-01 1 2007-02-01 2 2007-03-01 3 2007-04-01 4 2008-01-01 5 2008-03-01 dtype: datetime64 [ns] < p> Another edit : You can also parsing most dates with read_csv , but then you need to adjust your day (Note, my data is in the string named 'data'):

 in  [12]: df = pd.read_csv (StringIO (data), header = true, parse_dates = ['Date': ['Year', 'Month']}) [13]: df ['date'] = df ['date'] values.astype ('datetime64 [m]') [14]: DF Out [14]: Date 2007-01-01 1 2007-02-01 2 2 007-03-01 3 2007-04-01 4 2008-01-01 5 2008-03-01    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -