File size: 1,046 Bytes
fbff2aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb0fa8a
fbff2aa
 
 
bb0fa8a
fbff2aa
 
bb0fa8a
fbff2aa
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import pandas as pd
import os

try:
    df = pd.read_csv('data_with_keywords.csv')
    print("CSV Headers:", df.columns.tolist())
    
    if 'id' in df.columns:
        print("\nFirst 5 rows (ID vs ID from Index):")
        # standard index is 0..N
        for idx, row in df.head(5).iterrows():
            print(f"Index: {idx} | ID Column: {row['id']} | Name: {row['nama']}")
            
        print("\nLast 5 rows:")
        for idx, row in df.tail(5).iterrows():
            print(f"Index: {idx} | ID Column: {row['id']} | Name: {row['nama']}")
            
        # Check alignment
        mismatch = df[df.index != df['id']]
        if not mismatch.empty:
            print(f"\nMismatch found! {len(mismatch)} rows have Index != ID")
            print("Example Mismatch:")
            print(mismatch[['id', 'nama']].head(3))
        else:
            print("\nIndex matches ID exactly!")
            
    else:
        print("\n'id' column NOT FOUND in CSV. Pure index usage.")
        
except Exception as e:
    print(f"Error: {e}")