In [1]:
import tushare as ts
import pandas as pd
import numpy as np
from xpinyin import Pinyin
In [2]:
df=ts.get_stock_basics()
df.head(5)
att=df.columns.values.tolist()
#clommun_show = ['name', 'pe', 'outstanding', 'totals', 'totalAssets', 'liquidAssets', 'fixedAssets',
#'esp', 'bvps', 'pb', 'perundp', 'rev', 'profit', 'gpr', 'npr', 'holders']
pin=Pinyin()
df['UP'] = None
for index, row in df.iterrows():
name_str = df.name[index]
#print(name_str)
up_letter = pin.get_initials(name_str,u'')
#print(up_letter)
df.at[index,['UP']]=up_letter
#df[df['UP']=='HTGD']
df['code']=df.index
#print(df.UP)
code,代码 name,名称 industry,所属行业 area,地区 pe,市盈率 outstanding,流通股本(亿) totals,总股本(亿) totalAssets,总资产(万) liquidAssets,流动资产 fixedAssets,固定资产 reserved,公积金 reservedPerShare,每股公积金 esp,每股收益 bvps,每股净资 pb,市净率 timeToMarket,上市日期 undp,未分利润 perundp, 每股未分配 rev,收入同比(%) profit,利润同比(%) gpr,毛利率(%) npr,净利润率(%) holders,股东人数 ['name', 'pe', 'outstanding', 'totals', 'totalAssets', 'liquidAssets', 'fixedAssets', 'esp', 'bvps', 'pb', 'perundp', 'rev', 'profit', 'gpr', 'npr', 'holders']
In [3]:
col_show = ['name', 'open', 'pre_close', 'price', 'high', 'low', 'volume', 'amount', 'time', 'code']
initial_letter = ['HTGD','OFKJ','CDKJ','ZJXC','GXKJ','FHTX','DZJG']
code =[]
for letter in initial_letter:
code.append(df[df['UP']==letter].code[0])
#print(code)
if code != '': #not empty != ''
df_price = ts.get_realtime_quotes(code)
#print(df_price)
#df_price.columns.values.tolist()
df_price[col_show]
Out[3]:
In [4]:
from matplotlib.mlab import csv2rec
In [5]:
df=ts.get_k_data("002456",start='2018-01-05',end='2018-01-09')
df.to_csv("temp.csv")
r=csv2rec("temp.csv")
#r.date
In [6]:
import time, datetime
#str = df[df.code == '600487'][clommun_show].name.values
#print(str)
today=datetime.date.today()
yesterday = today - datetime.timedelta(1)
#print(today, yesterday)
i = datetime.datetime.now()
print ("当前的日期和时间是 %s" % i)
print ("ISO格式的日期和时间是 %s" % i.isoformat() )
print ("当前的年份是 %s" %i.year)
print ("当前的月份是 %s" %i.month)
print ("当前的日期是 %s" %i.day)
print ("dd/mm/yyyy 格式是 %s/%s/%s" % (i.day, i.month, i.year) )
print ("当前小时是 %s" %i.hour)
print ("当前分钟是 %s" %i.minute)
print ("当前秒是 %s" %i.second)
In [7]:
import time
localtime = time.localtime(time.time())
print("本地时间为 :", localtime)
# 格式化成2016-03-20 11:45:39形式
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
# 格式化成Sat Mar 28 22:24:24 2016形式
print(time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()))
In [8]:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import calendar
cal = calendar.month(2019, 3)
#print (cal)