I have a csv file with just one column 'date' formatted as integer:
| date |
|---|
| 20181231 |
| 20190107 |
| 20210329 |
| ... |
The solution would be to split the integer into different columns to represent day, month, year and quarter, like:
| date | day | month | year | quarter |
|---|---|---|---|---|
| 20181231 | 31 | 12 | 2018 | 4 |
| 20190107 | 07 | 01 | 2019 | 1 |
| 20210329 | 29 | 03 | 2021 | 2 |
| ... | ... | ... | ... | ... |
I would appreciate every kind of solution but I should resolve it using a python program without using pandas library.
So I write something like this:
import csv
reader = csv.reader(open('date.csv', 'r'))
writer = csv.writer(open('datesplit.csv', 'w'))
for line in reader:
year = line[0][:3]
month = line[0][4:5]
day = line[0][6:]
writer.writerow(year)
writer.writerow(month)
writer.writerow(day)
it is not working a you can imagine,
Thanks for helping