更新TDX自定义数据

Posted rongye

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了更新TDX自定义数据相关的知识,希望对你有一定的参考价值。

import urllib.request;
from pandas import DataFrame;
from pandas import Series;
from bs4 import BeautifulSoup;
import pandas as pd

file_name = "2222.txt"
file_path = file:///F:/python/untitled1/core/do_data/
response = urllib.request.urlopen(file_path + file_name)
html = response.read();
soup = BeautifulSoup(html,"html.parser")
trs = soup.find_all(tr)
ths = trs[0].find_all(th);

index_d = []
for th in ths:
    index_d.append(th.getText())
data = DataFrame(columns=index_d)
print(index_d)

for tr in trs :
    tds = tr.find_all(td)
    td_datas = []
    for td in tds:
        td_datas.append(td.getText())
    if len(td_datas) != 0:
        data=data.append(
            Series(
                td_datas,
                index=index_d
            ), ignore_index=True
        )

print(len(data))

str2s = []

for i in range(len(data["股票全码"])):

    str2 = data["涨停时间"][i] +" "+ data["历史涨停原因"][i] +" "+ data["涨停选原因"][i]
    str2s.append(str2)

data["new"] = str2s
data=data.drop_duplicates(subset=[股票代码],keep=last,inplace=False)
print(len(data))

new_data = pd.read_table("extern_user.txt",header= None,sep="|",encoding=utf-8,dtype=str)
new_data = new_data.iloc[:,0:4]
new_data = new_data.dropna()

new_data.columns.name = ["a","b","c","d"]
new_data.columns = ["a","b","c","d"]
for i in range(len(data)):
#for i in range(10):
    d_code = str(data.loc[i,"股票代码"])
    #new_data.loc[((new_data["b"] == d_code) &  (new_data["c"] == "31")),"d"]=data.loc[i,"new"]

    flag = ‘‘
    if d_code[0] == "6":
        flag = "1"
    else:
        flag = "0"
    row=[flag,d_code,"31",data.loc[i,"new"]]
    print(row)
    new_data = new_data.append(
            Series(
                row,
                index=new_data.columns
            ), ignore_index = True
    )


new_data = new_data.drop_duplicates(subset=["b","c"],keep=last,inplace=False)

new_data["c"]=new_data["c"].astype(int)
new_data = new_data.sort_values(by=["c","b"] , ascending=(True,True))

print(new_data.columns)
new_data=new_data.reset_index(drop=True)

new_data["e"]="0.00"


new_data.to_csv(save/extern_user.txt, sep=|, index=False,header=None,)

 

以上是关于更新TDX自定义数据的主要内容,如果未能解决你的问题,请参考以下文章

自定义对话框片段

如何在 Toad for Oracle 中使用自定义代码片段?

使用自定义支持片段将 getMap 替换为 getMapAsync

VSCode自定义代码片段——CSS选择器

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段(vue主模板)