import pandas as pd
start_date = ['2019-06-03', '2019-06-13', '2019-10-01', '2019-09-01']
end_date = ['2019-08-31', '2019-06-21', '2019-10-25', '2019-12-25']
data = pd.DataFrame(list(zip(start_date,end_date)), columns = ['Start Date', 'End Date'])
data
Start Date | End Date | |
---|---|---|
0 | 2019-06-03 | 2019-08-31 |
1 | 2019-06-13 | 2019-06-21 |
2 | 2019-10-01 | 2019-10-25 |
3 | 2019-09-01 | 2019-12-25 |
holiday_dates = [pd.datetime(2019, 8, 15), pd.datetime(2019, 10, 2), pd.datetime(2019, 10, 8),
pd.datetime(2019, 10, 28), pd.datetime(2019, 12, 25)]
import pandas as pd
import numpy as np
data = pd.DataFrame(np.random.rand(4, 3)*100,
columns=['Physics','Çhemistry','Maths'],
index = ['Student 1', 'Student 2','Student 3','Student 4'])
data
Physics | Çhemistry | Maths | |
---|---|---|---|
Student 1 | 59.488944 | 14.888411 | 52.794760 |
Student 2 | 21.872113 | 66.481646 | 87.190572 |
Student 3 | 9.885919 | 54.449674 | 58.696036 |
Student 4 | 33.804378 | 6.286295 | 30.373699 |
RoundUpto2Decimal = lambda x: round(x,2)
data.applymap(RoundUpto2Decimal)
Physics | Çhemistry | Maths | |
---|---|---|---|
Student 1 | 59.49 | 14.89 | 52.79 |
Student 2 | 21.87 | 66.48 | 87.19 |
Student 3 | 9.89 | 54.45 | 58.70 |
Student 4 | 33.80 | 6.29 | 30.37 |
There are multiple ways in pandas by which a dataframe can be indexed i.e, selecting particular set of rows and columns from a dataframe. For a detailed description over this topic, once can refer official pandas documentation - Indexing and Selecting Data
We’ll discuss the following -
Let’s begin with loading a sample dataset and required python packages.
import pandas as pd
import numpy as np
#Fetching data from url as csv by mentioning values of various paramters
data = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data",
header = None,
index_col = False,
names = ['sepal_length','sepal_width','petal_length','petal_width','iris_class'])
# visualising first five rows of sample dataset (Iris)
data.head()
The sample first five rows of data looks like (can be viewed using data.head())-
sepal_length | sepal_width | petal_length | petal_width | iris_class | |
---|---|---|---|---|---|
0 | 5.1 | 3.5 | 1.4 | 0.2 | Iris-setosa |
1 | 4.9 | 3.0 | 1.4 | 0.2 | Iris-setosa |
2 | 4.7 | 3.2 | 1.3 | 0.2 | Iris-setosa |
3 | 4.6 | 3.1 | 1.5 | 0.2 | Iris-setosa |
4 | 5.0 | 3.6 | 1.4 | 0.2 | Iris-setosa |