selik / xport

Python reader and writer for SAS XPORT data transport files.
MIT License
49 stars 23 forks source link

Edit value of 1 column #23

Closed sbjain closed 5 years ago

sbjain commented 5 years ago

Hi, in order to edit the value of 1 column in a file - do we need to configure pandas python package?

What is example code to access and change the value of 1 column? Please advise since the tutorial says not the same as CSV and only shows mapping example.

Thanks, Sagar

selik commented 5 years ago

Changing a value is not related to the xport module. This module reads a file and creates basic Python objects.

Changing a variable:

x = 1
x = 2

Changing a value in a list:

x = [1, 2]
x[0] = 3

Changing a value in a dict:

x = {"a": 1}
x["a"] = 2

The pandas module can help with tables, but I think a list comprehension might serve just as well for your task.

sbjain commented 5 years ago

Ok but what is approach using xport, do I need pandas or can be done another way for this?

On Jan 17, 2019, at 6:59 AM, Michael Selik notifications@github.com wrote:

Changing a value is not related to the xport module.

Changing a variable:

x = 1 x = 2 Changing a value in a list:

x = [1, 2] x[0] = 3 Changing a value in a dict:

x = {"a": 1} x["a"] = 2 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

selik commented 5 years ago

I'm not sure how else to explain it without doing the work for you. The xport reader creates basic Python objects from an XPT file. The xport writer creates an XPT file from basic Python objects. Your question is about basic Python objects, not the xport module.

As I said, I'll get around to writing documentation that could illustrate this for you, but that'll be some months from now. Maybe this summer. In the meantime, maybe you could try Coursera, Udacity, Datacamp, or one of the other ways to learn basic Python.

sbjain commented 5 years ago

Yes Michael a bit of guidance would be very appreciated. Xport happens to be first python module I am using.

Using xport how can I access specific column? The online documentation says not the same as CSV. Please show example of how I would access column 1 using xport.

Many thanks, Sagar

On Jan 17, 2019, at 10:47 AM, Michael Selik notifications@github.com wrote:

Closed #23.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

selik commented 5 years ago

Sorry, @sbjain, I'm not available for guidance for your first Python project.

sbjain commented 5 years ago

Hi Michael,

That is fine. Can you show an example though of how to use xport to edit column. Document says not same as CSV (which I am familiar with).

Thanks, Sagar

On Jan 17, 2019, at 11:44 AM, Michael Selik notifications@github.com wrote:

Sorry, @sbjain, I'm not available for guidance for your first Python project.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

selik commented 5 years ago

I'll do that in August. Thanks for pointing out the lack of examples in the docs.