金融量化学习---Python, MySQL, Pandas

这里用来记录一些在金融领域,尤其是银行相关的资金、债券、票据中应用到的数据管理与分析, 编程等心得或笔记,以及个人的一点小小兴趣(易经八卦、藏密禅修)等

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

python中的简易表格prettytable

安装:pip install PrettyTable

普通表格

from prettytable import PrettyTable
table = PrettyTable(['编号','云编号','名称','IP地址'])
table.add_row(['1','server01','服务器01','172.16.0.1'])
table.add_row(['2','server02','服务器02','172.16.0.2'])
table.add_row(['3','server03','服务器03','172.16.0.3'])
table.add_row(['4','server04','服务器04服务器04','172.16.0.4'])
table.add_row(['5','server05','服务器05','172.16.0.5'])
table.add_row(['6','server06','服务器06','172.16.0.6'])
table.add_row(['7','server07','服务器07','172.16.0.7'])
table.add_row(['8','server08','服务器08','172.16.0.8'])
table.add_row(['9','server09','服务器09','172.16.0.9'])
print(table)

定义函数打印dataframe

from prettytable import PrettyTable
def print_pretty(df0):
    df=df0.reset_index(inplace=False)
    columns=list(df.columns)
    table = PrettyTable(columns)
    rowNum = df.shape[0]
    for i in range(0,rowNum-1):
        table.add_row(list(df.iloc[i]))
    print(table.get_string(align="r"))

SQL数据库表转prettytable

import sqlite3 as lite
from prettytable import from_db_cursor

con = lite.connect('data.db')
with con:
    cur = con.cursor()    
    cur.execute('SELECT * FROM Cities')   
    x = from_db_cursor(cur) 
print(x)

CSV转prettytable

import sys
from prettytable import PrettyTable
from prettytable import from_csv 
reload(sys)
sys.setdefaultencoding('utf8')

table = PrettyTable()
fp = open("res.csv", "r") 
table = from_csv(fp) 
print(table)
fp.close()

详细参阅:
https://geek-docs.com/python/python-tutorial/python-prettytable.html
https://linuxops.org/blog/python/prettytable.html
https://blog.csdn.net/xc_zhou/article/details/81458740

posted on   chengjon  阅读(765)  评论(0编辑  收藏  举报

编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
点击右上角即可分享
微信分享提示