修复bug, 只转换数值类型
This commit is contained in:
@@ -53,14 +53,12 @@ def parse_data(data_file_path: str):
|
||||
data = json.loads(json_str)
|
||||
inner_temp_df = pd.DataFrame(data["data"]["diff"])
|
||||
df_list.append(inner_temp_df)
|
||||
logger.info(inner_temp_df)
|
||||
temp_df = pd.concat(df_list, ignore_index=True)
|
||||
temp_df["f3"] = pd.to_numeric(temp_df["f3"], errors="coerce")
|
||||
temp_df.sort_values(by=["f3"], ascending=False, inplace=True, ignore_index=True)
|
||||
temp_df.reset_index(inplace=True)
|
||||
temp_df["index"] = temp_df["index"].astype(int) + 1
|
||||
col_name_map = {
|
||||
"index": "序号",
|
||||
"f12": "代码",
|
||||
"f14": "名称",
|
||||
"f2": "最新价",
|
||||
@@ -82,6 +80,11 @@ def parse_data(data_file_path: str):
|
||||
new_cols = col_name_map.values()
|
||||
temp_df = temp_df[new_cols]
|
||||
for col in new_cols:
|
||||
if col in [
|
||||
"代码",
|
||||
"名称",
|
||||
]:
|
||||
continue
|
||||
temp_df[col] = pd.to_numeric(temp_df[col], errors="coerce")
|
||||
return temp_df
|
||||
|
||||
@@ -99,4 +102,7 @@ def get_index_latest_data():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
get_index_latest_data()
|
||||
df = get_index_latest_data()
|
||||
code = "000001"
|
||||
df = df[df["代码"] == code]
|
||||
print(df)
|
||||
|
||||
Reference in New Issue
Block a user