Is it not allowed to specify the variable df_{code} = pd.read_html(str(table))?

Asked 2 years ago, Updated 2 years ago, 16 views

import pandas as pd

import requests

from bs4 import BeautifulSoup


# A function that makes the event code pretty
def make_code(x):

    x = str(x)
    x = x.zfill(6)
    return x

# Obtaining the event code
url_comp_code = "http://kind.krx.co.kr/corpgeneral/corpList.do?method=download&searchType=13&marketType=%s"

code_data = pd.read_html(url_comp_code, header=0)[0]

code_data = code_data ["stock code", "company name"]

code_data["stock code"] = code_data["stock code"].apply(make_code)



# Apply item code to url
for num, code in enumerate (code_data["entry code")):

    fs_url = "http://comp.fnguide.com/SVO2/ASP/SVD_Main.asp?pGB=1&gicode=A{}&cID=&MenuYn=Y&ReportGB=&NewMenuID=101&stkGb=701".format(code)

    fs_page = requests.get(fs_url)

    soup = pd.read_html(fs_page.text, "lxml")

    table = soup.find_all("table")

    df_{code} = pd.read_html(str(table))

    # Zero NaN value for table

    for i in range(len(df_{code})):

        df[i].fillna(0,inplace=True)

    print(df_{code}[0])

I'm getting an error, I think it's because I set it like df_{code} = pd.read_html(str(table)) Can't I specify a variable like this?

I'd appreciate it if you could answer me.

Please give me a solution, too.

python

2022-09-20 19:03

1 Answers

df_{code} = pd.read_html(str(table)) I think it's because you set it like this, but can't I specify a variable like this?

I can't.


2022-09-20 19:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.