Related Articles

Related Articles

Determine Period Index and Column for DataFrame in Pandas
  • Last Updated : 25 Oct, 2020

In Pandas to determine Period Index and Column for Data Frame, we will use the pandas.period_range() method. It is one of the general functions in Pandas which is used to return a fixed frequency PeriodIndex, with day (calendar) as the default frequency.

Syntax: pandas.to_numeric(arg, errors=’raise’, downcast=None)

Parameters:
start : Left bound for generating periods
end : Right bound for generating periods
periods : Number of periods to generate
freq : Frequency alias
name : Name of the resulting PeriodIndex

Returns: PeriodIndex

Example 1:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import pandas as pd
  
  
  
course = ["DBMS", "DSA", "OOPS",
          "System Design", "CN", ]
  
# pass the period and staring index
webinar_date = pd.period_range('2020-08-15', periods=5)
  
# Determine Period Index and Column
# for DataFrame
df = pd.DataFrame(course, index=webinar_date, columns=['Course'])
  
df

chevron_right


Output:



Example 2:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import pandas as pd
  
day = ["Sun", "Mon", "Tue",
       "Wed", "Thurs", "Fri", "Sat"]
  
# pass the period and staring index
daycode = pd.period_range('2020-08-15', periods=7)
  
# Determine Period Index and Column for DataFrame
df = pd.DataFrame(day, index=daycode, columns=['day'])
  
df

chevron_right


Output:

Example 3:

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

import pandas as pd
  
Team = ["Ind", "Pak", "Aus"]
  
# pass the period and staring index
match_date = pd.period_range('2020-08-01', periods=3)
  
# Determine Period Index and Column for DataFrame
df = pd.DataFrame(Team, index=match_date, columns=['Team'])
  
df

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up
Recommended Articles
Page :