Untitled
unknown
plain_text
8 months ago
1.3 kB
7
Indexable
import json
# Read file content
with open('Scheme_details.txt', 'r') as f:
content = f.read()
# Parse JSON content
data = json.loads(content)
# It appears the top-level key is 'Table'
if 'Table' in data:
records = data['Table']
df = pd.DataFrame(records)
else:
df = pd.DataFrame(data)
print('Columns in dataframe:', df.columns.tolist())
# Identify scheme code column. Likely it is 'schemecode'.
scheme_code_col = None
for col in df.columns:
if col.lower().replace('_', '').replace(' ', '') in ['schemecode', 'scheme']:
scheme_code_col = col
break
print('Scheme code column identified as:', scheme_code_col)
# If not found, print available columns
if scheme_code_col is None:
print('Available columns: ', df.columns.tolist())
# Filter for scheme codes in {21521, 21651, 19575}
if scheme_code_col is not None:
filtered_df = df[df[scheme_code_col].isin([21521, 21651, 19575])]
print('Filtered rows:', len(filtered_df))
if not filtered_df.empty:
# Extract primary_fd_code values
result = filtered_df['primary_fd_code'].tolist()
print('Primary_fd_code(s) for requested scheme codes:', result)
else:
print('No rows found with the specified scheme codes')
print('done')Editor is loading...
Leave a Comment