March 2017
Beginner to intermediate
866 pages
18h 4m
English
The
read_csv method can be put to a variety of uses. Let us look at some such use cases.
Sometimes it is easier and viable to pass the directory address and filename as variables to avoid hard-coding. More importantly so, when one doesn't want to hardcode the full address of the file and intend to use this full address many times. Let us see how we can do so while importing a dataset.
import pandas as pd path = 'E:/Personal/Learning/Datasets/Book' filename = 'titanic3.csv' fullpath = path+'/'+filename data = pd.read_csv(fullpath)
For such cases, alternatively, one can use the following snippet that uses the path.join method in an os package:
import pandas as pd ...