Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
AniPython committed Feb 26, 2021
0 parents commit 593c195
Show file tree
Hide file tree
Showing 439 changed files with 311,067 additions and 0 deletions.
124 changes: 124 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/


/yi*
/ajaja
/lllll

/.idea
*.zip
/exportToHTML
199 changes: 199 additions & 0 deletions A001_课程简介/A001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
"""
输出
/Users/Yi/我的python教程/pandas办公自动化_备课/data_out/2019全平台销售总表.xlsx
"""
import pandas as pd
import numpy as np
import os
import sys
from time import time

from openpyxl import load_workbook
from openpyxl.drawing.image import Image

pd.options.display.max_columns = 888
pd.options.display.max_rows = 888

out_xlsx_title_1 = ['货号', '商品名称', '图片', '尺码', '日期', '售卖价',
'实收金额', '销售量_含拒退', '销售量_不含拒退',
'平台',
'品牌', '成本', '季节', '商品年份']


# 函数运行时间装饰器
def use_time(func):
def wrapper(*args, **kwargs):
start = time()
result = func(*args, **kwargs)
use = round(time() - start, 3)
print('%s()用时: %s秒' % (func.__name__, use))
return result

return wrapper


# 向 excel 插入图片
def save_image_to_excel(file_path, picture_path, columns, sheet_index=0):
"""
把图片插入到xlsx
:param file_path: 文件路径
:param picture_path: 图片路径
:param columns: 2D_list, [[0, B], [2, D]]表示: 依据第0列, 插入到到B列; 依据第2列, 插入到到D列
:param sheet_index: 选择sheet, 从0开现
:return: None
"""
print('插入图片...')
# img_path = '//10.1.4.184/g/data/picture/X89113075049.png'
# wb = load_workbook(r'G:\yi\yi_code\hxfs_data_y\my_module\1.xlsx')
df = pd.read_excel(file_path, sheet_index=sheet_index)
wb = load_workbook(file_path)
ws = wb.worksheets[sheet_index]
for depend_col, insert_col in columns:
depend_list = df.iloc[:, depend_col].tolist()
for idx, pic_name in enumerate(depend_list, start=1):
try:
img = Image(os.path.join(picture_path, pic_name + '.jpg'))
except:
try:
img = Image(os.path.join(picture_path, pic_name + '.png'))
except:
continue
anchor = insert_col + str(idx + 1)
ws.add_image(img, anchor=anchor)
wb.save(file_path)
print('插入图片完成')


def concat_files(folder):
"""
读取文件夹内的所有表格, 合并成一个表
:param folder: 文件夹路径
:return: DataFrame
"""
df_list = []
for fn in os.listdir(folder):
ffn = os.path.join(folder, fn)
if '.xlsx' not in ffn:
continue
# print(ffn)
df_temp = pd.read_excel(ffn)
df_list.append(df_temp)
df = pd.concat(df_list)
return df


# ['货号', '商品名称', '尺码', '日期', '售卖价', '实收金额', '销售量_含拒退', '销售量_不含拒退']
def read_sales_b():
"""
['款号颜色代码', '商品名称', '尺码', '日期', '售卖价', '活动价', '销售量_含拒退', '销售量_不含拒退']
"""
df_b = concat_files(
'./PlatformB'
)
df_b['实收金额'] = np.where(df_b['活动价'] == 0, df_b['售卖价'], df_b['活动价'])
df_b = df_b.rename(columns={'款号颜色代码': '货号'})
df_b = df_b.drop(columns=['活动价'])
return df_b


@use_time
def out_sales_summary_tb():
print('输出"2019全平台销售总表.xlsx"...')
df_a = concat_files('./PlatformA')
df_a['平台'] = '平台A'
df_b = read_sales_b()
df_b['平台'] = '平台B'
df_all = df_a.append(df_b)
# ['售卖价', '商品名称', '实收金额', '尺码', '平台',
# '日期', '货号', '销售量_不含拒退', '销售量_含拒退']
# print(df_all.head())
df_base = pd.read_excel(
'商品基础信息表.xlsx',
usecols=['货号', '品牌', '成本', '季节', '商品年份']
)
df_all = pd.merge(df_all, df_base, on='货号', how='left',
validate='many_to_one')
df_all['日期'] = df_all['日期'].dt.date
# print(df_all.head())

df_all.to_excel('./data_out/2019全平台销售总表.xlsx', index=None)
# df_all.to_pickle('./data_out/2019全平台销售总表.pkl')
print('输出"2019全平台销售总表.xlsx"完成', end='\n**********\n')


# 压缩图片
@use_time
def compress_image(src_path, dst_path, w=80, h=80):
print('压缩图片...')
src_fn_set = set(os.listdir(src_path))
dst_fn_set = set(os.listdir(dst_path))
fn_set = src_fn_set - dst_fn_set
if len(fn_set) == 0:
print('无可更新图片', end='\n**********\n')
return

from PIL import Image
for fn in fn_set:
src_ffn = os.path.join(src_path, fn)
dst_ffn = os.path.join(dst_path, fn)

larger_img = Image.open(src_ffn)
small_img = larger_img.resize((w, h), resample=Image.ANTIALIAS)
small_img.save(dst_ffn)

print(src_ffn)
print(dst_ffn)
print('压缩图片完成', end='\n**********\n')


"""
输出
./data_out/2019销售汇总表.xlsx
"""
out_xlsx_title = ['货号', '商品名称', '图片', '总销量', '总销售额',
'总成本', '总利润']


@use_time
def out_goods_id_total():
print('输出"2019销售汇总表.xlsx"...')
# df = pd.read_pickle('./data_out/2019全平台销售总表.pkl')
df = pd.read_excel('./data_out/2019全平台销售总表.xlsx')
# print(df.head())
df = df[['货号', '商品名称', '实收金额', '销售量_不含拒退', '成本']]
df = df.rename(columns={'销售量_不含拒退': '总销量'})
df['总销售额'] = df['实收金额'] * df['总销量']
df = pd.pivot_table(
df,
index=['货号', '商品名称', '成本'],
values=['总销量', '总销售额'],
aggfunc=sum)
df = df.reset_index()
df['总成本'] = df['总销量'] * df['成本']
df['总利润'] = df['总销售额'] - df['总成本']

total_series = df[['总销量', '总销售额', '总成本', '总利润']].sum(axis=0).reindex(out_xlsx_title)
total_series['货号'] = '合计'
# print(total_series)
# return
df = df.append(total_series, ignore_index=True)

df = df.reindex(columns=out_xlsx_title)
# print(df)
ffn = './data_out/2019销售汇总表.xlsx'
df.to_excel(ffn, index=None)
# 插入图片
picture_path = './压缩图'
save_image_to_excel(ffn, picture_path, [[0, 'C']])
print('输出"2019销售汇总表.xlsx"完成', end='\n**********\n')


if __name__ == '__main__':
# 1: 压缩图片
compress_image('./原图', './压缩图')

# 2: 输出"2019全平台销售总表.xlsx"
out_sales_summary_tb()

# 3: 输出"2019销售汇总表.xlsx"
out_goods_id_total()
Binary file added A001_课程简介/A001_课程简介_1.pdf
Binary file not shown.
Binary file added A001_课程简介/A001_课程简介_2.pdf
Binary file not shown.
Binary file added A001_课程简介/PlatformA/1.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/10.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/11.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/12.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/2.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/3.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/4.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/5.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/6.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/7.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/8.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformA/9.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/1.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/10.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/11.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/12.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/2.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/3.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/4.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/5.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/6.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/7.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/8.xlsx
Binary file not shown.
Binary file added A001_课程简介/PlatformB/9.xlsx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added A001_课程简介/压缩图/AGDH5500.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/AXTB3200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/FLHR1800.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/HWLA4700.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/LCHM9800.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/PWDK9200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/QTVW5600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/UQNA9200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/VBOY1800.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/XDQV5600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/XHQA3700.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/压缩图/YZFM1200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/AGDH5500.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/AXTB3200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/FLHR1800.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/HWLA4700.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/LCHM9800.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/PWDK9200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/QTVW5600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/UQNA9200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/VBOY1800.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/XDQV5600.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/XHQA3700.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/原图/YZFM1200.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added A001_课程简介/商品基础信息表.xlsx
Binary file not shown.
5 changes: 5 additions & 0 deletions A002_pandas简介/A002.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy as np

a = np.array([[1, 2], [3, 4]])
print(a)
print(type(a))
Binary file added A002_pandas简介/A002_pandas简介.pdf
Binary file not shown.
Binary file not shown.
Binary file added A005_create_Series/A005_创建Series.pdf
Binary file not shown.
Loading

0 comments on commit 593c195

Please sign in to comment.