In [11]:
# Import a library called Pandas and assigns it to the alias "pd".  This is a standard convention.
import pandas as pd

In [27]:
# Call a built-in Pandas function called .read_csv() to create a new spreadsheet-like object (i.e., a dataframe).
df = pd.read_csv('resources/sample_data.csv')

In [28]:
# Print the spreadsheet for easy viewing.
df


Out[28]:
Name Date Item Product Category Time (hrs) Amt Picked (lbs) Sale Value ($/lb)
0 Lucas 1/5/17 Green Apple Apples 2 5 2.5
1 Valter 1/5/17 European Pear Pears 4 10 2.0
2 Erik 1/5/17 Red Apple Apples 2 3 2.1
3 Georg 1/5/17 Asian Pear Pears 8 15 3.8
4 Lucas 1/5/17 Red Apple Apples 6 6 3.6

In [29]:
# Create a dictionary called item_name_changes and populate it with key/value pairs.
item_name_changes = {'European Pear':'Continental Fruit', 'Red Apple':'Pomme Rouge'}

In [30]:
# Call the dataframe's built-in .replace() function on the Item column to change the item names
df['Item'].replace(item_name_changes, inplace=True)

In [25]:
df['Amt Picked (g)'] = [row*2 for row in df['Amt Picked (lbs)']]

In [61]:
def convert_lb_to_gram(x):
    result = x*453.592
    return '{:.2f}'.format(result)

In [62]:
[convert_lb_to_gram(row) for row in df['Amt Picked (lbs)']]


Out[62]:
['2267.96', '4535.92', '1360.78', '6803.88', '2721.55']

In [60]:
['{:.2f}'.format(convert_lb_to_gram(row)) for row in df['Amt Picked (lbs)']]


Out[60]:
['2267.96', '4535.92', '1360.78', '6803.88', '2721.55']

In [ ]: