In [35]:
import pandas as pd
import numpy as np

columns = ["State","State_ANSI", "Ag_District", "Ag_District_Code", "County", 
           "County_ANSI","Commodity","Data_Item", "Domain", "Domain_Category", "Value", "CV", "FIPS"]

path = 'berries_by_county.csv'

berry_df = pd.read_csv(path, names=columns, skiprows=1)

In [36]:
# make strings to concatenate into FIPS codes
berry_df.State_ANSI = berry_df.State_ANSI.astype(str)
berry_df.County_ANSI = berry_df.County_ANSI.astype(str)

# more readable in title case than all caps
berry_df.State = berry_df.apply(lambda x: x.State.title(), axis = 1)
berry_df.County = berry_df.apply(lambda x: x.County.title(), axis = 1)
berry_df.Commodity = berry_df.apply(lambda x: x.Commodity.title(), axis = 1)

In [37]:
def prepend_zeros(row):
    if len(row.County_ANSI) == 1:
        return ''.join(['00', row.County_ANSI])
    elif len(row.County_ANSI) == 2:
        return ''.join(['0', row.County_ANSI])
    else:
        return row.County_ANSI

berry_df.County_ANSI = berry_df.apply(prepend_zeros, axis=1)

In [38]:
# index by combined ids
berry_df.FIPS = berry_df.apply(lambda row: ''.join([row.State_ANSI, row.County_ANSI]), axis = 1)
berry_df.head()


Out[38]:
State State_ANSI Ag_District Ag_District_Code County County_ANSI Commodity Data_Item Domain Domain_Category Value CV FIPS
0 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS - ACRES GROWN TOTAL NOT SPECIFIED 5 88.1 1001
1 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 30.4 1001
2 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS, IRRIGATED - ACRES GROWN TOTAL NOT SPECIFIED (D) (D) 1001
3 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS, IRRIGATED - OPERATIONS WITH AREA... TOTAL NOT SPECIFIED 4 37.4 1001
4 Alabama 1 BLACK BELT 40 Autauga 001 Blueberries BLUEBERRIES, TAME - ACRES GROWN TOTAL NOT SPECIFIED 5 88.9 1001

5 rows × 13 columns


In [62]:
berry_df2 = berry_df.Data_Item.apply(lambda x: pd.Series(x.split(' - ')))
berry_df2.columns = ['Spec_Commodity', 'Measure']
berry_df2.head()


Out[62]:
Spec_Commodity Measure
0 BERRY TOTALS ACRES GROWN
1 BERRY TOTALS OPERATIONS WITH AREA GROWN
2 BERRY TOTALS, IRRIGATED ACRES GROWN
3 BERRY TOTALS, IRRIGATED OPERATIONS WITH AREA GROWN
4 BLUEBERRIES, TAME ACRES GROWN

5 rows × 2 columns


In [63]:
berry_df3 = pd.merge(berry_df, berry_df2, left_index= True, right_index= True)

In [64]:
berry_df3.head()


Out[64]:
State State_ANSI Ag_District Ag_District_Code County County_ANSI Commodity Data_Item Domain Domain_Category Value CV FIPS Spec_Commodity Measure
0 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS - ACRES GROWN TOTAL NOT SPECIFIED 5 88.1 1001 BERRY TOTALS ACRES GROWN
1 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 30.4 1001 BERRY TOTALS OPERATIONS WITH AREA GROWN
2 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS, IRRIGATED - ACRES GROWN TOTAL NOT SPECIFIED (D) (D) 1001 BERRY TOTALS, IRRIGATED ACRES GROWN
3 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS, IRRIGATED - OPERATIONS WITH AREA... TOTAL NOT SPECIFIED 4 37.4 1001 BERRY TOTALS, IRRIGATED OPERATIONS WITH AREA GROWN
4 Alabama 1 BLACK BELT 40 Autauga 001 Blueberries BLUEBERRIES, TAME - ACRES GROWN TOTAL NOT SPECIFIED 5 88.9 1001 BLUEBERRIES, TAME ACRES GROWN

5 rows × 15 columns


In [65]:
# isolate Value column for rows that correspond to fresh market acres harvested, create boolean mask
test_series = berry_df3[berry_df3.Measure == "ACRES GROWN"].Value.str.contains("(D)")

# proportion of True/Total
float(np.sum(test_series))/len(test_series)


Out[65]:
0.5315918921211094

Would have liked to use acres grown, but 53% of that data has been withheld, as denoted by '(D)' values in Value column.

From USDA Census Report, Appendix A:

DISCLOSURE REVIEW

After tabulation and review of the aggregates, a comprehensive disclosure review was conducted. NASS is obligated to withhold, under Title 7, U.S. Code, any total that would reveal an individual’s information or allow it to be closely estimated by the public. Cell suppression was used to protect the cells that were determined to be sensitive to a disclosure of information. Farm counts are not considered sensitive and are not subject to disclosure controls.

Based on agency standards, data cells were determined to be sensitive to a disclosure of information if they violated either of two criteria rules. The threshold rule was violated if the data cell contained less than three operations. For example, if only one farmer produced turkeys in a county, NASS could not publish the county total for turkey inventory without disclosing that individual’s information. The dominance rule was violated if the distribution of the data within the cell allowed a data user to estimate any respondent’s data too closely. For example, if there are many farmers producing turkeys in a county and some of them were large enough to dominate the cell total, NASS could not publish the county total for turkey inventory without risking disclosing an individual respondent’s data. In both of these situations, the data were suppressed and a “(D)” was placed in the cell in the census publication table. These data cells were referred to as primary suppressions.


In [43]:
# IF WANT TO USE ACRES HARVESTED: replace null code Values (such as '(D)','(Z)', etc) with 0
#berry_df3.Value = berry_df3.Value.replace(to_replace = r'([A-Z+])', value = 0, regex=True)

In [66]:
berry_df4 = berry_df3[(berry_df3.Measure == "OPERATIONS WITH AREA GROWN") & (berry_df3.Spec_Commodity != "BERRY TOTALS, IRRIGATED")]
berry_df4.head()


Out[66]:
State State_ANSI Ag_District Ag_District_Code County County_ANSI Commodity Data_Item Domain Domain_Category Value CV FIPS Spec_Commodity Measure
1 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 30.4 1001 BERRY TOTALS OPERATIONS WITH AREA GROWN
5 Alabama 1 BLACK BELT 40 Autauga 001 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 34.1 1001 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
7 Alabama 1 BLACK BELT 40 Dallas 047 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 30.4 1047 BERRY TOTALS OPERATIONS WITH AREA GROWN
11 Alabama 1 BLACK BELT 40 Dallas 047 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 1 58.4 1047 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
13 Alabama 1 BLACK BELT 40 Dallas 047 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 34.1 1047 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN

5 rows × 15 columns


In [67]:
# replace null values with 0
berry_df4.Value = berry_df4.Value.fillna(0)

berry_df4.Value = berry_df4.Value.replace(to_replace = ',', value = '', regex=True)


/Users/agswigart/anaconda/envs/myenv/lib/python2.7/site-packages/pandas/core/generic.py:1830: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_index,col_indexer] = value instead
  self[name] = value

In [68]:
berry_df4.Value = berry_df4.Value.astype(int)
berry_df4.FIPS = berry_df4.FIPS.astype(int)

In [69]:
berry_df4.head()


Out[69]:
State State_ANSI Ag_District Ag_District_Code County County_ANSI Commodity Data_Item Domain Domain_Category Value CV FIPS Spec_Commodity Measure
1 Alabama 1 BLACK BELT 40 Autauga 001 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 30.4 1001 BERRY TOTALS OPERATIONS WITH AREA GROWN
5 Alabama 1 BLACK BELT 40 Autauga 001 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 34.1 1001 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
7 Alabama 1 BLACK BELT 40 Dallas 047 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 30.4 1047 BERRY TOTALS OPERATIONS WITH AREA GROWN
11 Alabama 1 BLACK BELT 40 Dallas 047 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 1 58.4 1047 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
13 Alabama 1 BLACK BELT 40 Dallas 047 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 34.1 1047 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN

5 rows × 15 columns


In [70]:
# check out California berrygies
berry_df4[berry_df4.State == 'California'].head(50)


Out[70]:
State State_ANSI Ag_District Ag_District_Code County County_ANSI Commodity Data_Item Domain Domain_Category Value CV FIPS Spec_Commodity Measure
1067 California 6 CENTRAL COAST 40 Alameda 001 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 8 13.5 6001 BERRY TOTALS OPERATIONS WITH AREA GROWN
1071 California 6 CENTRAL COAST 40 Alameda 001 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 7 24.8 6001 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1073 California 6 CENTRAL COAST 40 Alameda 001 Raspberries RASPBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 21.9 6001 RASPBERRIES OPERATIONS WITH AREA GROWN
1075 California 6 CENTRAL COAST 40 Alameda 001 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 13.9 6001 STRAWBERRIES OPERATIONS WITH AREA GROWN
1077 California 6 CENTRAL COAST 40 Contra Costa 013 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 48.5 6013 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1079 California 6 CENTRAL COAST 40 Contra Costa 013 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 22 13.5 6013 BERRY TOTALS OPERATIONS WITH AREA GROWN
1083 California 6 CENTRAL COAST 40 Contra Costa 013 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 1 24.8 6013 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1085 California 6 CENTRAL COAST 40 Contra Costa 013 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 21.1 6013 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
1087 California 6 CENTRAL COAST 40 Contra Costa 013 Boysenberries BOYSENBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 8 39.9 6013 BOYSENBERRIES OPERATIONS WITH AREA GROWN
1089 California 6 CENTRAL COAST 40 Contra Costa 013 Currants CURRANTS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 32.7 6013 CURRANTS OPERATIONS WITH AREA GROWN
1091 California 6 CENTRAL COAST 40 Contra Costa 013 Loganberries LOGANBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 37.2 6013 LOGANBERRIES OPERATIONS WITH AREA GROWN
1093 California 6 CENTRAL COAST 40 Contra Costa 013 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 10 13.9 6013 STRAWBERRIES OPERATIONS WITH AREA GROWN
1095 California 6 CENTRAL COAST 40 Lake 033 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 48.5 6033 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1097 California 6 CENTRAL COAST 40 Lake 033 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 15 13.5 6033 BERRY TOTALS OPERATIONS WITH AREA GROWN
1101 California 6 CENTRAL COAST 40 Lake 033 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 3 24.8 6033 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1103 California 6 CENTRAL COAST 40 Lake 033 Currants CURRANTS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 32.7 6033 CURRANTS OPERATIONS WITH AREA GROWN
1105 California 6 CENTRAL COAST 40 Lake 033 Raspberries RASPBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 14 21.9 6033 RASPBERRIES OPERATIONS WITH AREA GROWN
1107 California 6 CENTRAL COAST 40 Lake 033 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 13.9 6033 STRAWBERRIES OPERATIONS WITH AREA GROWN
1109 California 6 CENTRAL COAST 40 Marin 041 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 48.5 6041 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1111 California 6 CENTRAL COAST 40 Marin 041 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 15 13.5 6041 BERRY TOTALS OPERATIONS WITH AREA GROWN
1115 California 6 CENTRAL COAST 40 Marin 041 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 4 24.8 6041 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1117 California 6 CENTRAL COAST 40 Marin 041 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 21.1 6041 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
1119 California 6 CENTRAL COAST 40 Marin 041 Raspberries RASPBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 6 21.9 6041 RASPBERRIES OPERATIONS WITH AREA GROWN
1121 California 6 CENTRAL COAST 40 Marin 041 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 13.9 6041 STRAWBERRIES OPERATIONS WITH AREA GROWN
1123 California 6 CENTRAL COAST 40 Monterey 053 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 48.5 6053 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1125 California 6 CENTRAL COAST 40 Monterey 053 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 121 13.5 6053 BERRY TOTALS OPERATIONS WITH AREA GROWN
1129 California 6 CENTRAL COAST 40 Monterey 053 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 23 24.8 6053 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1131 California 6 CENTRAL COAST 40 Monterey 053 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 4 21.1 6053 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
1133 California 6 CENTRAL COAST 40 Monterey 053 Boysenberries BOYSENBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 8 39.9 6053 BOYSENBERRIES OPERATIONS WITH AREA GROWN
1135 California 6 CENTRAL COAST 40 Monterey 053 Loganberries LOGANBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 2 37.2 6053 LOGANBERRIES OPERATIONS WITH AREA GROWN
1137 California 6 CENTRAL COAST 40 Monterey 053 Raspberries RASPBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 24 21.9 6053 RASPBERRIES OPERATIONS WITH AREA GROWN
1139 California 6 CENTRAL COAST 40 Monterey 053 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 99 13.9 6053 STRAWBERRIES OPERATIONS WITH AREA GROWN
1141 California 6 CENTRAL COAST 40 Napa 055 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 13 13.5 6055 BERRY TOTALS OPERATIONS WITH AREA GROWN
1145 California 6 CENTRAL COAST 40 Napa 055 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 1 24.8 6055 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1147 California 6 CENTRAL COAST 40 Napa 055 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 21.1 6055 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
1149 California 6 CENTRAL COAST 40 Napa 055 Raspberries RASPBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 21.9 6055 RASPBERRIES OPERATIONS WITH AREA GROWN
1151 California 6 CENTRAL COAST 40 Napa 055 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 6 13.9 6055 STRAWBERRIES OPERATIONS WITH AREA GROWN
1153 California 6 CENTRAL COAST 40 San Benito 069 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 3 48.5 6069 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1155 California 6 CENTRAL COAST 40 San Benito 069 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 13.5 6069 BERRY TOTALS OPERATIONS WITH AREA GROWN
1159 California 6 CENTRAL COAST 40 San Benito 069 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 5 13.9 6069 STRAWBERRIES OPERATIONS WITH AREA GROWN
1161 California 6 CENTRAL COAST 40 San Luis Obispo 079 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 8 48.5 6079 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1163 California 6 CENTRAL COAST 40 San Luis Obispo 079 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 87 13.5 6079 BERRY TOTALS OPERATIONS WITH AREA GROWN
1167 California 6 CENTRAL COAST 40 San Luis Obispo 079 Blackberries BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES ... TOTAL NOT SPECIFIED 40 24.8 6079 BLACKBERRIES, INCL DEWBERRIES & MARIONBERRIES OPERATIONS WITH AREA GROWN
1169 California 6 CENTRAL COAST 40 San Luis Obispo 079 Blueberries BLUEBERRIES, TAME - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 25 21.1 6079 BLUEBERRIES, TAME OPERATIONS WITH AREA GROWN
1171 California 6 CENTRAL COAST 40 San Luis Obispo 079 Boysenberries BOYSENBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 15 39.9 6079 BOYSENBERRIES OPERATIONS WITH AREA GROWN
1173 California 6 CENTRAL COAST 40 San Luis Obispo 079 Currants CURRANTS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 1 32.7 6079 CURRANTS OPERATIONS WITH AREA GROWN
1175 California 6 CENTRAL COAST 40 San Luis Obispo 079 Raspberries RASPBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 31 21.9 6079 RASPBERRIES OPERATIONS WITH AREA GROWN
1177 California 6 CENTRAL COAST 40 San Luis Obispo 079 Strawberries STRAWBERRIES - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 36 13.9 6079 STRAWBERRIES OPERATIONS WITH AREA GROWN
1179 California 6 CENTRAL COAST 40 San Mateo 081 Berries, Other BERRIES, OTHER - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 4 48.5 6081 BERRIES, OTHER OPERATIONS WITH AREA GROWN
1181 California 6 CENTRAL COAST 40 San Mateo 081 Berry Totals BERRY TOTALS - OPERATIONS WITH AREA GROWN TOTAL NOT SPECIFIED 24 13.5 6081 BERRY TOTALS OPERATIONS WITH AREA GROWN

50 rows × 15 columns


In [71]:
# Create pivot table
berry_pt = pd.pivot_table(berry_df4, values = 'Value', rows = 'FIPS', cols= 'Commodity', aggfunc = np.sum)

Lots of NaN values in the pivot table. Will convert to zeros.


In [72]:
berry_pt.head()


Out[72]:
Commodity Berries, Other Berry Totals Blackberries Blueberries Boysenberries Cranberries Currants Loganberries Raspberries Strawberries
FIPS
1001 NaN 5 NaN 5 NaN NaN NaN NaN NaN NaN
1003 1 41 9 33 NaN NaN NaN NaN NaN 5
1005 NaN 5 NaN 5 NaN NaN NaN NaN NaN NaN
1007 NaN 2 NaN 2 NaN NaN NaN NaN NaN NaN
1009 NaN 25 2 18 NaN NaN NaN NaN 1 6

5 rows × 10 columns


In [73]:
berry_pt = berry_pt.fillna(0)
berry_pt.head()


Out[73]:
Commodity Berries, Other Berry Totals Blackberries Blueberries Boysenberries Cranberries Currants Loganberries Raspberries Strawberries
FIPS
1001 0 5 0 5 0 0 0 0 0 0
1003 1 41 9 33 0 0 0 0 0 5
1005 0 5 0 5 0 0 0 0 0 0
1007 0 2 0 2 0 0 0 0 0 0
1009 0 25 2 18 0 0 0 0 1 6

5 rows × 10 columns


In [75]:
berry_pt.to_csv('berries.csv')