I am working with a dataset that comes in with nonsense field names in the first row, with the actual field names in the second row.
Currently I'm using this script:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('CAR_551.csv')
df1 = df.iloc[1:,:]
print(df1.head(10))
df1.info()
The dataset appears to be successfully updated. When I print the dataset the first row is gone, however when I call df1.info() it still returns the original headers. Example output:
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 StartDate 10 non-null object
1 EndDate 10 non-null object
2 Status 10 non-null object
3 IPAddress 10 non-null object
4 Progress 10 non-null object
5 Duration (in seconds) 10 non-null object
6 Finished 10 non-null object
7 RecordedDate 10 non-null object
8 ResponseId 10 non-null object
9 RecipientLastName 0 non-null object
10 RecipientFirstName 0 non-null object
11 RecipientEmail 0 non-null object
12 ExternalReference 0 non-null object
13 LocationLatitude 10 non-null object
14 LocationLongitude 10 non-null object
15 DistributionChannel 10 non-null object
16 UserLanguage 10 non-null object
17 Q6#1_1 10 non-null object
18 Q6#1_2 10 non-null object
19 Q6#1_3 10 non-null object
20 Q6#1_4 10 non-null object
21 Q6#1_5 10 non-null object
22 Q6#1_6 10 non-null object
23 Q6#1_7 10 non-null object
24 Q6#1_8 10 non-null object
25 Q6#1_9 10 non-null object
26 Q6#2_1 10 non-null object
27 Q6#2_2 10 non-null object
28 Q6#2_3 10 non-null object
29 Q6#2_4 10 non-null object
30 Q6#2_5 10 non-null object
31 Q6#2_6 10 non-null object
32 Q6#2_7 10 non-null object
33 Q6#2_8 10 non-null object
34 Q6#2_9 10 non-null object
35 Q8 10 non-null object
36 Q9 10 non-null object
dtypes: object(37)
memory usage: 3.0+ KB
These are all field names from the first row of the dataset. Is there a way to get this to update and show the field names from row 2 of the data?
Can someone explain the underlying mechanism of what's going on here? How is the first row even stored in the new dataframe at all if I specified only the second row on should be included when I declared the variable?