Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Python to Combine CSV Elements From Columns to Rows
    text
    copied!<p>(Actual input CSV is comma-delimited as normal; I just showed my ideas as tables for ease of viewing.)</p> <p>Here's an example of what I want to do using Python 2.7 (Pandas if it's better/easier, but I also like learning python logic and pandas skips over a lot, though I may have to learn it for stuff like this):</p> <p>From</p> <pre><code>Price Name Text Number Choice URL Email $40 Foo Stuff 560 Y www.a.com a@a.com $60 Foo Things 280 N www.a.com a@a.com $20 Foo Other 120 Y www.a.com a@a.com $25 John Gals 1222 N www.b.com b@b.com $100 Bar Dudes 999 Y www.c.com c@c.com $250 Bar Guys 200 Y www.c.com c@c.com </code></pre> <p>To</p> <pre><code>Name Price1 Price2 Price3 Text1 Text2 Text3 Number1 Number2 Number3 Choice1 Choice2 Choice3 URL Email Foo $40 $60 $20 Stuff Things Other 560 280 120 Y N Y www.a.com a@a.com John $25 Gals 1222 N www.b.com b@b.com Bar $100 $250 Dudes Guys 999 200 Y Y www.c.com c@c.com </code></pre> <p>The order of the columns doesn't matter, though I would like to combine by the name column as a rule. (Hopefully I got them right, as just the example was a pain!)</p> <p>For extra credit, I'd love to stop a cell from populating a new column if it's blank: e.g. if <code>a@a.com</code> was missing from row 2 in <code>From</code> above, <code>To</code> would look the same, not spawn a "Email2" column. Also, while the order of columns doesn't matter (I'm using this to populate a database that requires CSV input), the numbering has to match up! That is, for any given name, e.g. Foo above: $60, Things, 280, and N all have to be in columns marked "[OrigName]2" - and no Column2 should be populated while a column1 is blank for any given label.</p> <p>This should be easy, but for completeness, I also need a column that adds up the filled Text columns (e.g., integer column "Number of Texts") and another one that adds up the number of "Price"s marked "Free" (e.g., "Number of Free Texts").</p> <p>Thanks so much for any help - I'm already excited for what I'll learn from this, and further reading resources are always welcome!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload