Accepted answer

Does this work?

import pandas as pd
# Read in data frame from clipboard
df = pd.read_clipboard()
df = df.replace(df.iloc[1][1:],'null')

        Date  colA  colB
0  12-Sep-14    20    40
1  13-Sep-14  null  null
2  14-Sep-14    12   -20
3  15-Sep-14    74    43

Here, df.iloc[1] gives access to row 1



gives json without the ""



Code as below:

import numpy as np

# create null/NaN value with np.nan
df.loc[1, colA:colB] = np.nan

Here's the explanation:

  1. locate the entities that need to be replaced: df.loc[1, colA:colB] means selecting row 1 and columns from colA to colB;
  2. assign the NaN value np.nan to the specific location.


Try using NaN which is the Pandas missing value:

df = pd.read_clipboard()
df.colA.iloc[1] = NaN

instead of NaN you could also use None. Note that neither of these terms are entered with quotes.

Then you can use to_json() to get your output:


Related Query

More Query from same tag