Python Forum

Full Version: Turning column of 8 digit numbers into three seperate columns
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In this problem I imported data from an excel file. Turned that dataframe into a numpy array. My assignment tells me to replace the entire first column of values into three columns. So basically a 1000 rows of dates formatted YYYYMMDD into YYYY MM DD.

I indexed the first of my array and it's about 1000 rows formated as 8 digit dates. I have tried indexing parts of that number and storing them in a variable. The problem with that is I can only index a range of values. Not just the first four numbers of the 8 digit date.

My professor didn't really give my class any notes on how to turn one column of values into 3. I also tried converting the entire column into a string but that doesn't seem to help. I can only index individual dates. Not the entire column.

I just need a push in the right direction.

 import numpy as np 
import pandas



gcdata = pandas.read_excel('govt_camp_2013_01_to_2016_03.xlsx' , 'Sheet1' , header =0 , usecols = 'C:F' )

gcdata = gcdata.values

date = gcdata[:,0]

date = date.reshape(len(date),1)
Could you show a couple (not the whole file) of lines of data
like 1st through 3rd