Before importing the external files, you need to keep in mind:
- Whether data contains header row or not.
Install and Load pandas Package
Pandas is a powerful package for data analysis. It makes data manipulation task easy. With Pandas, you can load your data into data frames, select columns for specific value etc.
If you are using Jupyter Notebook or Spyder IDE,then you can install pandas by using the following command:
If you are using Anaconda, you can write the following command to install pandas:
1. Import csv data in python
It is important to note that the file that you are going to read using pandas is in the specific location in your drive. To locate path of file and set working directory, you can use the following command:
To check the Current Working directory, you can use the following directory:
To get the csv file that I have used above, click here
Now you have set path of your file in your Notebook. The read_csv( ) is function to import csv data using pandas, You need to use the following command:
The above command is useful when you have header(title) in your data file. But if you have no header in your data, then you can use the command:
2. import data from excel in python
To read Excel file in pandas, you have to use read_excel( ) function in Python.
If the Excel file that you are importing has multiple sheets then you have to specify name of sheet in sheetname=option.
3. Import SAS data in python
You can read SAS data file by using read_sas( ) function in Python using the following command:
4. Import SQL file in python
You can read SQL database using the read_sql( ) function by using the following commands:
df= “SELECT * FROM Reviews;”
view = pd.read_csv(df, Con)
5. Import Text file in python
To read text file of data, you can use read_table( ) function or read_csv( ) with sept=”\t” to read data from tab-separated file. Use the following commands,
df = pd.read_csv(“data.txt”,sep=”\t”)
6. Import file from URL in python
If you want to read data from URL. Simply copy the url from browser and use the following command:
My intention with this post is to help out those who are willing to start their Machine Learning Journey and to get things work easily.
If you any have addition, then spread your words.