📜  确定 Pandas 中 DataFrame 的周期索引和列

📅  最后修改于: 2022-05-13 01:55:39.392000             🧑  作者: Mango

确定 Pandas 中 DataFrame 的周期索引和列

在 Pandas 中,我们将使用 pandas.period_range() 方法来确定数据框的周期索引和列。它是 Pandas 中的通用函数之一,用于返回固定频率的 PeriodIndex,以天(日历)作为默认频率。

示例 1:

Python3
import pandas as pd
 
 
 
course = ["DBMS", "DSA", "OOPS",
          "System Design", "CN", ]
 
# pass the period and starting 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


Python3
import pandas as pd
 
day = ["Sun", "Mon", "Tue",
       "Wed", "Thurs", "Fri", "Sat"]
 
# pass the period and starting 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


Python3
import pandas as pd
 
Team = ["Ind", "Pak", "Aus"]
 
# pass the period and starting 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


输出

示例 2:

蟒蛇3

import pandas as pd
 
day = ["Sun", "Mon", "Tue",
       "Wed", "Thurs", "Fri", "Sat"]
 
# pass the period and starting 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

输出:

示例 3:

蟒蛇3

import pandas as pd
 
Team = ["Ind", "Pak", "Aus"]
 
# pass the period and starting 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

输出