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]:
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]:
In [60]:
['{:.2f}'.format(convert_lb_to_gram(row)) for row in df['Amt Picked (lbs)']]
Out[60]:
In [ ]: