Wednesday, June 17, 2020

How to describe the categorical variables of Object type

In general, the Int and Float type values can be described as it hold numerical values using python pandas library . But how can we describe the categorical variables which are Object type. So, we have to filter out all the object type columns and apply describe function. The below code explains the same.

Example:

1. The int and float data type values can be described as follows:



2. The Object type values can be handled as follows:






















Thursday, June 11, 2020

How to generate the dates range from one to other

In general, pandas is good for time series and generate the date ranges:

Example 1:

import pandas as pd
dates1 = pd.date_range('11/06/2020', periods=7)
timeseries = pd.Series(np.arange(7), index=dates)
timeseries .to_csv(r'G:\DatascienceProjects\examples_datasets\tseries.csv')

Example 2:
import pandas as pd
date1 = '2020-05-03'
date2 = '2020-05-11'
mydates = pd.date_range(date1, date2).tolist()
Similarly, we can use bdate_range if you need only weekdays during the analysis.
Website for reference:

How to read excel sheets from file using python

1. The below transaction file has multple sheets in it. Now we are trying to read the Expense sheet name using python padas.

Syntax:

Readsheet= pd.read_excel(r'G:\DatascienceProjects\examples_datasets\transactions.xlsx', sheet_name = 'Expense') # Name of sheet to read from
#pd.read_excel()
Readsheet.head(3) 

Element wise operation on LIST vs ARRAY

The use of arrays over lists: You can write  vectorised  code on numpy arrays, not on lists, which is  convenient to read and write, and con...