Python Forum
Turning column of 8 digit numbers into three seperate columns
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turning column of 8 digit numbers into three seperate columns
#1
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)
Reply
#2
Could you show a couple (not the whole file) of lines of data
like 1st through 3rd
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Random Generator: From Word to Numbers, from Numbers to n possibles Words Yamiyozx 2 1,409 Jan-02-2023, 05:08 PM
Last Post: deanhystad
  list digit into number Voldyy 2 1,524 Jul-10-2022, 06:13 PM
Last Post: deanhystad
  List index out of range when turning CSV into dict ranbarr 15 6,408 May-12-2021, 10:38 AM
Last Post: ranbarr
  Convert list of numbers to string of numbers kam_uk 5 2,991 Nov-21-2020, 03:10 PM
Last Post: deanhystad
  Frequency in first digit from csv file, NO IMPORT bryan0901 6 2,825 May-28-2020, 09:50 AM
Last Post: bryan0901
  Four-digit number text translation. soz 3 2,670 May-13-2019, 03:02 PM
Last Post: buran
  create three digit numbers Krszt 4 4,464 Dec-09-2018, 03:12 PM
Last Post: ThePhi
  Sum of digit in a string MEH012 1 9,450 Apr-20-2018, 02:13 AM
Last Post: Larz60+
  Regular Expressions in Files (find all phone numbers and credit card numbers) Amirsalar 2 4,094 Dec-05-2017, 09:48 AM
Last Post: DeaD_EyE
  Allow only digit penoxcz 3 3,787 Nov-14-2017, 03:04 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020