In [27]:
import pandas
def add_full_name(path_to_csv, path_to_new_csv):
#Assume you will be reading in a csv file with the same columns that the
#Lahman baseball data set has -- most importantly, there are columns
#called 'nameFirst' and 'nameLast'.
#1) Write a function that reads a csv
#located at "path_to_csv" into a pandas dataframe, adds a new column
#called 'nameFull' with a players full name.
#
#For example:
# for Hank Aaron, nameFull would be 'Hank Aaron',
#
#2) Write the data in the pandas dataFrame to a new csv file located at
#path_to_new_csv
#WRITE YOUR CODE HERE
baseball_data = pandas.read_csv(path_to_csv)
baseball_data['nameFull'] = baseball_data['nameFirst'] + ' ' + baseball_data['nameLast']
baseball_data[:5]
baseball_data.to_csv(path_to_new_csv)
In [26]:
oldpath = "C:\Vindico\Projects\Data\Course\Python\Udacity\Introduction to Data Science\Lesson 2\Lecture\Lahman\Master.csv"
newpath = "C:\Vindico\Projects\Data\Course\Python\Udacity\Introduction to Data Science\Lesson 2\Lecture\Lahman\NewMaster.csv"
add_full_name(oldpath, newpath)