Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
import pandas as pd
Code #1 : read_csv is an important pandas function to read csv files and do operations on it.
Opening a CSV file through this is easy. But there are many others thing one can do through this function only to change the returned object completely. For instance, one can read a csv file not only locally, but from a URL through read_csv or one can choose what columns needed to export so that we don’t have to edit the array later.
Here is the list of parameters it takes with their Default values.
pd.read_csv(filepath_or_buffer, sep=’, ‘, delimiter=None, header=’infer’, names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, iterator=False, chunksize=None, compression=’infer’, thousands=None, decimal=b’.’, lineterminator=None, quotechar='”‘, quoting=0, escapechar=None, comment=None, encoding=None, dialect=None, tupleize_cols=None, error_bad_lines=True, warn_bad_lines=True, skipfooter=0, doublequote=True, delim_whitespace=False, low_memory=True, memory_map=False, float_precision=None)
Not all of them are much important but remembering these actually save time of performing same functions on own. One can see parameters of any function by pressing shift + tab in jupyter notebook. Useful ones are given below with their usage :
|filepath_or_buffer||URL or Dir location of file|
|sep||Stands for seperator, default is ‘, ‘ as in csv(comma seperated values)|
|index_col||Makes passed column as index instead of 0, 1, 2, 3…r
|header||Makes passed row/s[int/int list] as header
|use_cols||Only uses the passed col[string list] to make data frame|
|squeeze||If true and only one column is passed, returns pandas series|
|skiprows||Skips passed rows in new data frame|
Refer the link to data set used from here.
Code #2 :
- Python program to read CSV without CSV module
- Using csv module to read the data in Pandas
- How to read a CSV file to a Dataframe with custom delimiter in Pandas?
- Convert CSV to Excel using Pandas in Python
- Load CSV data into List and Dictionary using Python
- Create a GUI to convert CSV file into excel file using Python
- Convert CSV to JSON using Python
- How to Convert an image to NumPy array and saveit to CSV file using Python?
- Convert Text File to CSV using Python Pandas
- Creating a dataframe using CSV files
- How to skip rows while reading csv file using Pandas?
- Pandas - DataFrame to CSV file using tab separator
- Reading specific columns of a CSV file using Pandas
- Working with csv files in Python
- Reading CSV files in Python
- Convert JSON to CSV in Python
- Writing CSV files in Python
- Saving Text, JSON, and CSV to a File in Python
- Convert CSV to HTML Table in Python
- Writing data from a Python List to CSV row-wise
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.