You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
691 B
20 lines
691 B
import pandas as pd
|
|
import json
|
|
import ast # Python 的 ast.literal_eval 可以安全解析 Python 字典字符串
|
|
|
|
df = pd.read_csv("alpha_list.csv", nrows=5)
|
|
|
|
# 方法1:用 ast.literal_eval(推荐,能解析 Python 字面量)
|
|
for i, row in df.iterrows():
|
|
regular_str = row['regular']
|
|
if pd.notna(regular_str):
|
|
try:
|
|
regular_dict = ast.literal_eval(regular_str)
|
|
code = regular_dict.get('code', '')
|
|
print(f"Row {i}: {code[:80]}...")
|
|
except Exception as e:
|
|
print(f"Row {i}: 解析失败 - {e}")
|
|
|
|
# 方法2:看看原始字符串前200个字符
|
|
print("\n原始字符串示例:")
|
|
print(df.iloc[0]['regular'][:200]) |