1

I have yearly data sets with some missing data. I used this code to read but unable to omit white space present at the end of february. can anyone help to solve this problem?

df1 = pd.read_fwf('DQ404.7_77.txt',widths=ws,header=9, nrows=31, keep_default_na = False)
df1 = df1.drop('Day', 1)
df2 = np.array(df1).T 

what I want is to arrange all the data in one column with respect to date. My data is uploaded in this link you can download https://drive.google.com/open?id=0B2rkXkOkG7ExbEVwZUpHR29LNFE

what i wanted is to get time series data from this file and it should be like

Feb,25  13
Feb,26  13
Feb,27  13
Feb,28  13
March, 1    10
March, 2    10
March, 3    10

Not with empty strings in between february and March

5
  • Sorry are you asking how to remove rows where the entries are NaN or empty strings ''? Commented May 13, 2016 at 8:39
  • 1
    You've not included the definition for ws so your code is not runnable Commented May 13, 2016 at 8:40
  • @ EdChum no no I have defination of ws, and wanted to remove empty strings . and I have defined ws = [4,9,7,7,7,7,7,7,7,7,7,7,7] Commented May 13, 2016 at 8:46
  • So you want to drop the rows or replace empty strings with NaN? Commented May 13, 2016 at 8:49
  • hello EdChum, I want to drop empty strings, so that when I stack it should be regular Commented May 13, 2016 at 8:50

1 Answer 1

2

So after a lot of comments it looks like df[df != ''] works for you

Sign up to request clarification or add additional context in comments.

11 Comments

then we will miss the values from Jan and from other month...isn't it?
I asked you what you wanted you stated I want to drop empty strings, so that when I stack it should be regular dropping doesn't equal replacement so you've not explained clear enough what you want. So I ask again what do you want instead of empty strings? Do you want NaN or you want to forward fill from the last valid value?
sorry for not making it clear but , I want to forward fill from the last valid value
What about the other 'NA' values do you want these to be treated as NaN and forward filled?
So I ask again what was wrong with df[df['Feb.' != '']? or df[df != '']? and no it was not clear
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.