一、準備工作
解決lzma 告警問題(如果有):
yum install xz-devel
yum install python-backports-lzma
pip install backports.lzma
cd /usr/local/python3/lib/python3.8?
vim lzma.py
第27行修改:
try: from _lzma import * from _lzma import _encode_filter_properties, _decode_filter_propertiesexcept ImportError: from backports.lzma import * from backports.lzma import _encode_filter_properties, _decode_filter_properties
二、
pip install pandas
import pandas as pd
? 2
? 3 #讀取xlsx呵燕、xls數(shù)據(jù)
? 4 df = pd.read_excel('fruit2.xlsx')
? 5 print(df)
? 6 print(df.values)
? 7 print(df['名稱'])
? 8 print(df.loc[1])
? 9 print(df.loc[2,'單價/元'])
10
11 df = df.set_index('名稱')? #設置名稱列為行索引
12 print(df)
13 print(df.values)
14 print(df['庫存/kg'])
15 print(df.loc['蘋果'])
16 print(df.loc['香蕉','單價/元'])
17 #寫入xlsx、xls
18 writer = pd.ExcelWriter('pandas.xlsx')
19 df.to_excel(writer,'sheet1')
20 writer.save()