On Thu 20 Feb 2025 at 13:52:06 (-0600), Richard Owlett wrote:
> On 2/20/25 11:20 AM, debian-u...@howorth.org.uk wrote:
> > Richard Owlett <rowl...@access.net> wrote:
> > > I wish to extract CSV formatted data from a PDF document. [1]
> > > Page ES-7 has a weekly grocery list for males grouped by age.
> > > I need only the first and last columns.
> > > 
> > > Can someone point me in a suitable direction?
> > > 
> > > TIA
> > > 
> > > [1] https://www.fns.usda.gov/cnpp/thrifty-food-plan-2006
> > >       Table ES-1. Thrifty Food Plan market baskets, quantities of food
> > >        purchased for a week, by age-gender group, 2006

I don't read PDFs /in/ the browser: it downloads it instead.
So while held captive at home by the weather, I dragged the mouse
across the Males table and dumped it in a file.

I opened it in emacs, and adopted a strategy I've used before:
squeeze all whitespace to one char, concatenate those lines that
break column one,  s/, /=/  and  s/ /-/   skipping five occurrences
at the end of each line. (The table is small enough to not bother
automating that replacement.) I eliminated "years" at the top,
and the text at the bottom, and typed t at the beginning of each
line starting with a space. This all took about ten minutes.

I then typed   gnumeric es-7-1   to check it looked "rectangular"
(before spreading the columns, everything should line up),
selected the entire sheet, double-clicked once to spread the columns
to their natural width, and saved it. As you can see, I haven't
bothered to revert the character substitutions. If you /really/
want CSV, you'd have to quote that first column, or perform
the reversion after feeding it to /your/ spreadsheet program.

You're welcome to the files.

> > If you look at
> > https://www.fns.usda.gov/cnpp/thrifty-food-plan-2021 instead, you can
> > find the underlying data in spreadsheet form (.xlsx). Perhaps that will
> > be an adequate substitute?
> 
> You just demonstrated that "Murphy's Law" holds ;<
> 
> I click on the link you quoted in my default browser and a PDF is
> displayed [actually my original starting point months ago].
> 
> If I use my alternate browser {Firefox instead of SeaMonkey} I get to
> chose which of several files to view. {one of them is an .xlsx file}
> 
> Murphy gets a second jab in.
> The 2006 version has the data I want in a slightly different layout
> that the 2021 version. The first is a better match for how I do things
> ;/
> 
> Also the PDF structure of the two links react slightly differently
> when selecting with mouse movements/clicks. The 2006 version seems to
> allow me to select only what I want. [ 2021 version grabs everything
> between first and last click. 2006 appears to select only the columns
> of interest]

Did I understand you to have used two different browsers for the two
versions? If so, that might explain the different select experience.
As I said, I download PDFs, and dragging across them always gives me
a rectangular shaded area that is copied. (I might have been able to
save a few keystrokes by copying the food items and figures in two
copy/pastes, but as I said, the table is small.)

> Can't spend time right now to verify first impression. Will know more
> this weekend.
> 
> *THANK YOU*

Cheers,
David.
                                                                                
                 Males
Food category                                               12-13 years    
14-18 years        19-50 years        51-70 years        71+ years
Total pounds                                                   35.55           
38.59              39.86               37.38             34.02
                                                                                
          Pounds per week
Grains
Whole grain breads, rice, pasta, and pastries
   (including whole grain flours)                               1.24            
3.46               2.82                2.14              1.59
Whole grain cereals (including hot cereal mixes)                 .05            
  .18               .08                 .08               .06
Popcorn and other whole grain snacks                             .88            
  .00               .00                 .11               .00
Non-whole grain breads, cereal, rice, pasta, pies,
    pastries, snacks, and flours                                1.27            
1.08               1.66                1.65              1.17
                                                                3.43            
4.71               4.55                3.97              2.81
Vegetables
All potato products                                             1.61            
3.13               2.48                2.28              2.11
Dark-green vegetables                                            .87            
1.31               1.24                1.19              1.17
Orange vegetables                                                .67            
  .64               .98                 .81               .66
Canned and dry beans, lentils, and peas (legumes)               1.83            
2.00               1.87                2.16              1.35
Other vegetables                                                3.28            
1.47               2.70                3.18              2.67
                                                                8.25            
8.55               9.27                9.62              7.96
Fruits
Whole fruits                                                    3.70            
5.68               6.65                7.71              5.09
Fruit juices                                                    2.29            
1.83               1.76                 .44               .38
                                                                5.99            
7.51               8.41                8.14              5.47
Milk products
Whole milk, yogurt, and cream                                    .49            
  .84               .55                 .28               .23
Lower fat and skim milk and lowfat yogurt                      12.97           
10.97              10.75               11.01             11.41
All cheese (including cheese soup and sauce)                     .02            
  .08               .07                 .11               .02
Milk drinks and milk desserts                                    .00            
  .00               .00                 .05               .00
                                                               13.48           
11.89              11.37               11.46             11.65
Meat and beans
Beef, pork, veal, lamb, and game                                 .72            
  .54               .63                 .66               .47
Chicken, turkey, and game birds                                  .82            
  .77              2.55                 .84              3.55
Fish and fish products                                           .45            
  .26               .17                 .04               .21
Bacon, sausages, and luncheon meats (including spreads)          .02            
  .08               .02                 .01               .01
Nuts, nut butters, and seeds                                     .46            
  .41               .26                 .34               .35
Eggs and egg mixtures                                            .42            
  .34               .36                 .29               .06
                                                                2.89            
2.39               3.99                2.19              4.64
Other foods
Table fats, oils, and salad dressings                            .33            
1.00                .99                 .62               .46
Gravies, sauces, condiments, and spices                          .39            
1.68                .99                 .32               .46
Coffee and tea                                                   .00            
  .00               .01                 .03               .02
Soft drinks, sodas, fruit drinks, and ades
   (including rice beverages)                                    .02            
  .00               .00                 .38               .00
Sugars, sweets, and candies                                      .00            
  .07               .08                 .05               .01
Soups (ready-to-serve and condensed)                             .70            
  .79               .16                 .60               .53
Soups (dry)                                                      .00            
  .00               .02                 .00               .00
Frozen or refrigerated entrées (including pizza, fish sticks,
    and frozen meals)                                            .07            
  .00               .01                 .00               .00
                                                                1.51            
3.54               2.26                2.00              1.49
Notes: Food in as-purchased form, which includes uncooked grain products; raw, 
canned, and frozen vegetables; fruit juice concentrates; and meat
with bones.
The numbers are rounded; thus, when summed, they may not equal the respective 
totals.
Males

Food-category 12-13 14-18 19-50 51-70 71+

Total-pounds 35.55 38.59 39.86 37.38 34.02

Pounds-per-week

Grains

Whole-grain-breads=rice=pasta=and-pastries-(including-whole-grain-flours) 1.24 
3.46 2.82 2.14 1.59

Whole-grain-cereals-(including-hot-cereal-mixes) .05 .18 .08 .08 .06

Popcorn-and-other-whole-grain-snacks .88 .00 .00 .11 .00

Non-whole-grain-breads=cereal=rice=pasta=pies=pastries=snacks=and-flours 1.27 
1.08 1.66 1.65 1.17

t 3.43 4.71 4.55 3.97 2.81

Vegetables

All-potato-products 1.61 3.13 2.48 2.28 2.11

Dark-green-vegetables .87 1.31 1.24 1.19 1.17

Orange-vegetables .67 .64 .98 .81 .66

Canned-and-dry-beans=lentils=and-peas-(legumes) 1.83 2.00 1.87 2.16 1.35

Other-vegetables 3.28 1.47 2.70 3.18 2.67

t 8.25 8.55 9.27 9.62 7.96

Fruits

Whole-fruits 3.70 5.68 6.65 7.71 5.09

Fruit-juices 2.29 1.83 1.76 .44 .38

t 5.99 7.51 8.41 8.14 5.47

Milk-products

Whole-milk=yogurt=and-cream .49 .84 .55 .28 .23

Lower-fat-and-skim-milk-and-lowfat-yogurt 12.97 10.97 10.75 11.01 11.41

All-cheese-(including-cheese-soup-and-sauce) .02 .08 .07 .11 .02

Milk-drinks-and-milk-desserts .00 .00 .00 .05 .00

t 13.48 11.89 11.37 11.46 11.65

Meat-and-beans

Beef=pork=veal=lamb=and-game .72 .54 .63 .66 .47

Chicken=turkey=and-game-birds .82 .77 2.55 .84 3.55

Fish-and-fish-products .45 .26 .17 .04 .21

Bacon=sausages=and-luncheon-meats-(including-spreads) .02 .08 .02 .01 .01

Nuts=nut-butters=and-seeds .46 .41 .26 .34 .35

Eggs-and-egg-mixtures .42 .34 .36 .29 .06

t 2.89 2.39 3.99 2.19 4.64

Other-foods

Table-fats=oils=and-salad-dressings .33 1.00 .99 .62 .46

Gravies=sauces=condiments=and-spices .39 1.68 .99 .32 .46

Coffee-and-tea .00 .00 .01 .03 .02

Soft-drinks=sodas=fruit-drinks=and-ades-(including-rice-beverages) .02 .00 .00 
.38 .00

Sugars=sweets=and-candies .00 .07 .08 .05 .01

Soups-(ready-to-serve-and-condensed) .70 .79 .16 .60 .53

Soups-(dry) .00 .00 .02 .00 .00

Frozen-or-refrigerated-entrées-(including-pizza=fish-sticks=and-frozen-meals) 
.07 .00 .01 .00 .00

t 1.51 3.54 2.26 2.00 1.49

Attachment: es-7-1.gnumeric
Description: application/gnumeric

Reply via email to