Python Data Analysis -> pandas Fun excel-> (1) how to use the pandas to create a data file excel

# In the Spyder in Anaconda3
 
# Define pandas module pd
import pandas as pd
 
# Create a new DataFrame object that defines this object has two fields: ID and Name, there are three values ​​in each field
df=pd.DataFrame({'ID':[1,2,3],'Name':['Tim','Victor','Nick']})
 
ID # is defined as an index
df=df.set_index('ID')
 
# Excel file generating output.xlsx, and save the corresponding position. Note If you directly into the C drive may be a problem!
df.to_excel ( 'D: / python result /task1/output.xlsx')
 
# After the output Done!
print('Done!')

Guess you like

Origin www.cnblogs.com/zhangjianglin/p/11416858.html