Mac Excel created under python

Code
1. Create an empty table in python
import pandas as pd # poured pandas, pd arbitrary name can easily play
DF = pd.DataFrame ()
#DataFrame type data structure similar to the structure of the database tables, columns and comprising row index index.
df.to_excel ( 'C: \ Users \ yangyiming \ Desktop \ a.xls') # c without the Mac, and the disc, but also to add C at the head position, and / pasted to the entire position \. Info view file pathThe location information to select the copyThis after the copy is pasted path This is pasted after the copy path
2. adding a table information
import pandas as pd # poured pandas, pd arbitrary name can easily play
df = pd.DataFrame ({ 'id' : [1,2,3], 'name' : [ 'YS', 'ZY', 'kJ']})
#DataFrame type data structure similar to the structure of the database table, which contains the row and column indices. Typical data word created in the DataFrame (key refers to)
df.to_excel ( 'C: \ the Users \ yangyiming \ Desktop \ a.xls')
the new table of FIG., A column at 012 index. So how to ID him as an index which?
Here Insert Picture Description
3. Add one: df = df.set_index ( 'id' ) # id to the index of
Here Insert Picture Description
the complete code below
Import PANDAS AS PD
DF = pd.DataFrame ({ 'id': [l, 2,3], 'name' : [ 'YS', 'ZY', 'kJ']})
DF = df.set_index ( 'id') # id to the index
df.to_excel(‘C:\Users\yangyiming\Desktop\a.xls’)

Guess you like

Origin blog.csdn.net/qq_39008205/article/details/86592451