2

Thanks to Jeff, I could find the missing lines in my file data structure and fill the missing lines.

However, filled missing lines in output show "2013-07-01 00:00:00,,,,,,,,,,,,,,,,,,", not with nan. I would like to fill "NaN" or "nan" inside of commas.

My code is:

filin = DataPath + 'SKP_AWS_MIN_QC_10001_2013.07-09.DAT'
pd.set_option('max_rows',10)
data=pd.read_csv(filin,sep='#',index_col=[1],parse_dates=[1])
print data
index = pd.date_range('2013-07-01 00:00:00','2013-09-30 23:59:00',freq="T")
df = data
sk_f = df.reindex(index)
print sk_f
sk_f.to_csv("sample1.csv")

As long as I know from the information about reindex function, missing holes should be filled with something (default is "NaN"). I can't find the reason why missing hole in my result files are not filled.

Any idea or comment will be really appreciated.

Thank you, Isaac

Isaac
  • 885
  • 2
  • 15
  • 35

1 Answers1

2

It has nothing to do with the reindex(), when you to_csv, do provide a string for missing values if you don't want them to show up as blank spaces. Something like df.to_csv('temp.csv',na_rep='NaN') will do the trick.

If not provided, na_rep= defaults to ''

CT Zhu
  • 52,648
  • 17
  • 120
  • 133
  • @Andy Hayden Thank you for comment, but I can't find the way to check the best or correct answer. – Isaac Jun 27 '14 at 06:39