I have a CSV file called mrh.csv which has first two rows representing the header:
Name,Height,Age
"",Metres,""
A,-1,25
B,95,-1
I am using the following code to read it into DataFrame:
import pandas as pd
pd.read_csv('mrh.csv', header=[0,1], na_values=[-1,''])
This results in a Data Frame with the following contents:
Name Height Age
Unnamed: 0_level_1 Metres Unnamed: 2_level_1
0 A NaN 25.0
1 B 95.0 NaN
Using the na_values parameter of read_csv I can mark the missing values marked as -1 in the file, but the missing header row values, when marked as "" (I also tried -1) are displayed as Unnamed: x_level_y (or -1 if it is used instead).
Is there a way to not display the missing values - to remove the Unnamed: x_level_y or substitute it with a meaningful value?
Desired output 1:
Name Height Age
Metres
0 A NaN 25.0
1 B 95.0 NaN
Desired output 2:
Name Height Age
- Metres -
0 A NaN 25.0
1 B 95.0 NaN
a meaningful value, can you show the output you desire to get?