import pandas as pd
import numpy as np
cust_no = np.arange(111,555,111)
snapshot = list(range(201809,201813))
income = np.random.randint(50,5000,32)
expense = np.random.randint(10,1000,32)
df = pd.DataFrame(data = list(zip(cust_no, snapshot,income, expense)),
columns = ['cust_no','snapshot', 'income', 'expense'])
df.set_index('snapshot', inplace=True)
df
I want to change the title "snapshot" to "start_of_month". I could apply reset_index()
, change column title and then set_index()
. But seems like a lot of overkill.
有没有更简单的方法?
您可以使用此: