1628人加入学习
(19人评价)
Python数据分析 - Pandas玩转Excel

Python数据分析轻松学

价格 $99美元

一、涉及知识点

1、Excel和pandas创建excel格式的数据源

2、数据格式有很多,常见的如下:CSV文件、数据库表格、文件格式(Excel、PDF、Word等)、HTML文件、JSON文件、文本文件、XML文件

 

二、遇到的问题及原因

1、pandas库找不到(AttributeError: module 'pandas' has no attribute 'DataFrame'

原因:1)未安装pandas库

          2)pycharm中解释器配置错误(项目多时需要配置虚拟环境,每个虚拟环境中挂载的库都不一样,pycharm的setting中会有默认的配置,需检查是否错误)

 

[展开全文]

import pandas as pd

df=pd.DataFrame[{'ID':[1,2,3],'Name':['Tim','Victor','N}]

df.to_excel('C:/Temp/output.xlsx')

print('Done!')

[展开全文]
kuokung · 2019-01-18 · 创建文件 0

pandas is a package

How to use pandas to create an Excel file?

DataFrame(数据帧)

DataFrame is a very important Class in pandas, a DataFrame can be treated as a worksheet in Excel. Take care of the first letter "D" is upper case.

import pandas as pd

df = pd.DataFrame({'ID':[1,2,3],'Name':['Tim','Victor','Nick']})
df = df.set_index('ID')
print(df)
df.to_excel('C:/Temp/output.xlsx')
print('Done!')

'ID' and 'Name' is the name of the column. 

[1,2,3] and ['Tim','Victor','Nick'] is the record under column ID and Name.

Code:

DataFrame.set_index('ID')

is set the column ID as the index. otherwise, the DataFrame will add an additional column as the index.

Code:

DataFram.to_excel('C:/Temp/output.xlsx')

.to_excel is a method of Class DataFrame. that will create an excel file under an absolute address.

Result:


      Name
ID        
1      Tim
2   Victor
3     Nick
Done!

Process finished with exit code 0

 

[展开全文]
Lewin · 2018-10-11 · 创建文件 5

授课教师

Tim老师

课程特色

视频(30)
下载资料(25)

学员动态

Adamzyf 加入学习
Marstapeworm 加入学习
alpha 加入学习
elllen 完成了 Code for 002
elllen 开始学习 Code for 002