1. Create a dataframe from a dictionary
>>>ImportPandas>>> dict_a = {'user_id':['Webbang','Webbang','Webbang'],'book_id':['3713327','4074636','26873486'],'rating':['4','4','4'],'mark_date':['2017-03-07','2017-03-07','2017-03-07']}>>> df = Pandas. DataFrame (DICT_A)#Create a dataframe from a dictionary>>> DF#The created DF column names are sorted alphabetically by default, and the order in the dictionary is not the same, the dictionary is ' user_id ', ' book_id ', ' rating ', ' mark_date 'book_id mark_date Rating user_id03713327 2017-03-07 4Webbang1 4074636 2017-03-07 4Webbang2 26873486 2017-03-07 4 Webbang
2. Adjust column order
>>> df = df[['user_id','book_id',' Rating','mark_date'# Adjust the column order to ' user_id ', ' book_id ', ' Rating ', ' mark_date '>>> df user_id book_id rating mark_date0 Webbang 3713327 4 2017-03-071 webbang 4074636 4 2017-03-072 Webbang 26873486 4 2017-03-07
3. Adjust index to start from 1
# change Index to start from 1 >>> df user_id book_id rating mark_date1 webbang 3713327 4 2017-03-072 webbang 4074636 4 2017-03-073 Webbang 26873486 4 2017-03-07
Dataframe Operation Summary: http://www.cnblogs.com/huahuayu/p/8227494.html
Python Pandas. Dataframe adjusting column order and modifying the index name