#import pandas import pandas as pd
data = pd.read_csv("mushrooms.csv")
## now we have our data data.head()
5 rows × 23 columns
NoteIf your file is not in your current directory you will need to pass in the files directories path as an argument to read_csv
# Example where file is in a different directory data = pd.read_csv(r"C:\Users\Mostafa\My Files\Python\Kaggle\Mushrooms\mushrooms.csv")
data.head()
Your data may or may not have headers by default this method persumes that your data does have headers(column names) and it's the very first row of your data.
of course you can adjust this..let's look at some examples
in the example below I put header = None which means my data does not have column names, so it puts the column names in the data and assigns numerical values for your column names,
pd.read_csv("mushrooms.csv", header=None)
8125 rows × 23 columns
CSV file is seporated by a comma , so you don't need to use the sep parameter if your reading a csv file. But if your data is seporated by something else such ; , tab or anything you can still make use of read_csv() method and let the method know how your data is seporated so it knows how to delimit your dataset.
#example data = pd.read_csv("my_data.txt", sep=";") #or if its seporated by a tab, just put 8 spaces data = pd.read_csv("my_data.txt", sep=" ") #or maybe your seporated by something completley random symbol such as ^, just put that symbol data = pd.read_csv("my_data.txt", sep="^")