![]() |
split file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: split file (/thread-18569.html) |
split file - mcgrim - May-22-2019 I have a file with many rows. This is one of the lines: 2015-03-05 22:08:06.636451 2321 so in order to separate it, I wrote the following: from astral import Astral from scipy import * from pylab import* import numpy as np from numpy import array import matplotlib.pyplot as plt import datetime from datetime import timezone from datetime import timedelta import matplotlib.dates as dates import pandas as pd import pytz file=open('bird_jan25jan16.txt','r') #Turning datas in file into lists orig_date=[] orig_time=[] movements=[] for i in file: tempsplit=i.split(' ') orig_date.append(tempsplit[0]) orig_time.append(tempsplit[1]) movements.append(tempsplit[2])but when I print 'movements', I get I am assuming that the splitting is wrong, but not sure.How do I correct it? RE: split file - DeaD_EyE - May-22-2019 I think everything is answered here: https://python-forum.io/Thread-utc-to-central-european-time?pid=81208#pid81208 You have a blank line with many whitespaces. Use split without arguments. If your data is corrupt (blank lines/missing columns/too much), then put a use the split function in a try block, except ValueError and continue if this happens. Then this data is left out. When the format is wrong, it may end into a empty result ![]() |