Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't one read and write both csv's? #30

Closed
josiekre opened this issue Nov 15, 2015 · 4 comments
Closed

Why can't one read and write both csv's? #30

josiekre opened this issue Nov 15, 2015 · 4 comments

Comments

@josiekre
Copy link

I see in the help that writing to csv isn't allowed if reading from one (when using as a script). What is the reason for this? This is exactly what I was hoping to do. :)

I think I could facilitate this on my own by writing a python script to read my data first, use tzwhere internally, and then writing a csv. But I'm guessing that I'm missing something here otherwise you'd have implemented this.

@cstich
Copy link
Contributor

cstich commented Nov 17, 2015

The import/export options of the script are mainly there to convert between different types of input files if you want to do that, so it doesn't make a lot of sense to go from CSV to CSV file. The script options are not particularly useful from an end-user perspective, but they make it relatively painless to ship with the most up-to-date version of the timezone map (which reminds me that I have to update that), and see whether you broke anything before you commit.

I am not a 100% sure I understand what you exactly want to do, but if you could elaborate a bit that would be great. I feel like I am now the one that is missing something obvious :)

You don't want to export polygons with timezone information by any chance?

@josiekre
Copy link
Author

I simply need an offline way to append local time to a csv file with
lat/lon/timestamp (UTC). (Actually in my case it's a bunch of csv files at
once so I use glob.) I am doing analysis in R, and so in/out csv means I
can call it from R with 'system(python tzwhere.py)' and then call
'read_csv()" again easily to get the results back in. I've done a quick and
dirty implementation like so:

from tzwhere import tzwhere
import glob
import pandas as pd

def reader(f):
  d = pd.read_csv(f, names=['id', 'latitude', 'longitude', 'timestamp'])
  return d


def main():
  files = glob.glob('*.csv')
  data = pd.concat([reader(f) for f in files], ignore_index=True)
  tz = tzwhere.tzwhere(shapely=True)
  data['local_tz'] = data.apply(lambda row: tz.tzNameAt(row['latitude'],
                                                row['longitude']), axis=1)

  data.to_csv('to_r.csv', index=False)

if __name__ == "__main__":
  main()

---------- Forwarded message ----------
From: cstich notifications@github.com
Date: Tue, Nov 17, 2015 at 6:34 PM
Subject: Re: [pytzwhere] Why can't one read and write both csv's? (#30)
To: pegler/pytzwhere pytzwhere@noreply.github.com
Cc: Josie Kressner josie@transportfoundry.com

The import/export options of the script are mainly there to convert between
different types of input files if you want to do that, so it doesn't make a
lot of sense to go from CSV to CSV file. The script options are not
particularly useful from an end-user perspective, but they make it
relatively painless to ship with the most up-to-date version of the
timezone map (which reminds me that I have to update that), and see whether
you broke anything before you commit.

I am not a 100% sure I understand what you exactly want to do, but if you
could elaborate a bit that would be great. I feel like I am now the one
that is missing something obvious :)

You don't want to export polygons with timezone information by any chance?


Reply to this email directly or view it on GitHub
#30 (comment).

@cstich
Copy link
Contributor

cstich commented Nov 18, 2015

Your code makes sense to me as it is. Pandas is probably a much better choice for doing all the reading and writing of CSV files than using anything in pytzwhere for that. Does that answer your original question?

@josiekre
Copy link
Author

Sure thing. I'll continue to use the script with pandas.

@cstich cstich closed this as completed Nov 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants