Convert Daily data to Weekly data without losing names of other Column, using Python Pandas.

Raj Kumar
2 min readJan 5, 2021

Now let’s go straight to the point.

Here, We will see how we can convert daily data into weekly/monthly data without losing column names and dates as indexes.

I’m using “covid_19_india.csv” from Kaggle as our sample dataset with shape(9291,9). You can download it from the link below.

Let’s start and load our “covid_19_india.csv” dataset

Input 1:

Output:

As you can see above our dates are string types, so we need to convert them to DateTime type.

Input 2:

Output:

Now we can see that the Date column is in the date object. Also, we drop some columns to simplify the data. However, this is not necessary, while converting daily data to weekly/monthly/yearly it will drop categorical columns.

Input 3:

Output:

As you can see that our daily data is converted into weekly without losing names of other columns and dates as an index.

You can also convert to month just by using “m” instead of “w”. For Eg.:df.resample(“m”).mean() . ‘m’ for months.

Also, you can use mode(), sum(), etc., instead of mean() according to your preferences.

You can refer more about resample function by checking this page below :

--

--