python学习笔记:
打包程序: sudo pip3 install pyinstaller -> pyinstaller -F http.py
.astype('int') dataframe列float转int:
dataframe去重:.duplicated()
或:data.drop_duplicates(subset=['A','B'],keep='first',inplace=True)
网格线段:plt.grid(color = 'r', linestyle = '--', linewidth = 0.5)
安装python打包exe库:pip install pyinstaller
编译python源代码文件:pyinstaller -F app.py
通过 literal_eval实现str和字典互转:
user = '{"name" : "john", "gender" : "male", "age": 28}'#双引号
user_dict = ast.literal_eval(user)
print(user_dict)
在 QGIS-Console 中请求用户输入,您可以使用 QDialog 对象:
from PyQt5.QtWidgets import QInputDialog
def getTextInput(title, message):
answer = QInputDialog.getText(None, title, message)
if answer[1]:
print(answer[0])
return answer[0]
else:
return None
dataframe列字符串转化:.astype(str)
绘制折线图:
import matplotlib.pyplot as plt
y1=[10,13,5,40,30,60,70,12,55,25]
x1=range(0,10)
x2=range(0,10)
y2=[5,8,0,30,20,40,50,10,40,15]
plt.plot(x1,y1,label='Frist line',linewidth=3,color='r',marker='o',
markerfacecolor='blue',markersize=12)
plt.plot(x2,y2,label='second line')
plt.xlabel('Plot Number')
plt.ylabel('Important var')
plt.title('Interesting Graph\nCheck it out')
plt.legend()
plt.show()
语法链接:https://www.cnblogs.com/XiaMengJie/p/12538518.html
原文链接:https://blog.csdn.net/hecongqing/article/details/55522276
pd.set_option('Display.max_rows',None)#展示全部行
pd.set_option('Display.max_columns',None)#展示全部列
pd.set_option('display.width', 160) #最大显示宽度
close_price = data.current(context.symbol(instrument), 'close') #当收盘价
df1 = DataSource(time_instruments).\
read(start_date = today_date, end_date = today_date).set_index('date') #获取当日分钟数据
cancel_order(_order) #取消订单
# 当天第一根分钟行情到来时,打开交易标志位
if data.current_dt.strftime("%H%M%S") == "093100":
分钟数据获取
df = DataSource('bar1m_CN_STOCK_A').read(start_date='2019-01-01', end_date='2019-01-01', instruments=['600000.SHA'])
获取股票概念
df = D.history_data(D.instruments(), '2017-08-23', '2017-08-23', ['concept']).dropna() # 'concept' 是股票的概念字段
df['is_ai'] = df['concept'].map(lambda x: '' in x) # 以人工智能为例,找到相关概念股票
st = list(df[df['is_ai'] == True]['instrument'])
instrument_concept = D.history_data(st,'2017-08-23','2017-08-23',['name', 'concept'])
DataSource("stock_status_CN_STOCK_A").read(start_date='2007-01-04', end_date='2007-01-04') #所有股票状态
求数列中3的倍数
selected_numbers = list(filter(lambda x: x % 3 == 0, range(1, 11)))
表格取值函数
print(df[df['instrument'].apply(lambda x: x == '600584.SHA')])
{a=[[1,2,3],
[4,5,6]]
print("列表a如下:")
print(a)
print("增加一维,新维度的下标为0")
c=np.stack(a,axis=0)
print(c)
print("增加一维,新维度的下标为1")
c=np.stack(a,axis=1)
print(c)}
#DataFrame创建
matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
]
df = pd.DataFrame(matrix, columns=list('xyz'), index=list('abc'))
df.apply(np.square)
在Qt工程文件.pro中配置:
CONFIG += console
df['darden'] = df['close_1'].astype(int)
合并两表格
df = df.dropna() #去掉空值
df_a = pd.merge(df_t, df_y, left_on=['instrument'], right_on=['instrument'])
列表平均值:statistics.mean(rise_mean_all)
df_t = df_t.sort_values('rise_w', ascending=False) #排序
c++预处理器中加入:
_CRT_SECURE_NO_WARNINGS
获取最新行情:
DataArray<Tick>* tick = current("SHSE.000300");
cout << "price: " << tick->at(0).price << endl;
df_c['date'] = df_c.groupby('instrument')['date'].shift(-5)
#数据上移
//掘金获取全A股票代码示例 get_instruments(exchanges='SZSE,SHSE', sec_types=1, fields='symbol',df=1)['symbol'].tolist()
#均值、方差、标准差
import numpy as np
arr = [1,2,3,4,5,6]
#求均值
arr_mean = np.mean(arr)
#求方差
arr_var = np.var(arr)
#求标准差
arr_std = np.std(arr,ddof=1)