0

I have a data frame of apple stock data and Close column has a few "null" strings in it. I cannot plot my data because I keep getting 'Cannot convert string to...' error. When I try the code below I get an error 'AttributeError: 'DataFrame' object has no attribute 'close_arr'. This code was based on the answer provided in this thread How to drop rows from pandas data frame that contains a particular string in a particular column?

apl = pd.read_csv(path, index_col='Date', parse_dates=True)
close_arr = aapl['Close']
aapl = aapl[~aapl.close_arr.str.contains("null")]
aapl.head()

Here is the info()

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 9234 entries, 1980-12-12 to 2017-07-26
Data columns (total 6 columns):
Adj Close    9234 non-null object
Close        9234 non-null object
High         9234 non-null object
Low          9234 non-null object
Open         9234 non-null object
Volume       9234 non-null object
dtypes: object(6)
memory usage: 505.0+ KB

I have also tried:

aapl = aapl[~aapl['Close'].str.contains("null")]

Where am I going wrong here?

user3088202
  • 2,714
  • 5
  • 22
  • 36
  • 1
    Provide us with an example of your code by e.g. apl.head().to_dict() – Anton vBR Jul 27 '17 at 17:29
  • My code is included in the question. – user3088202 Jul 27 '17 at 17:32
  • 1
    @user3088202 Your df.head() would help. – cs95 Jul 27 '17 at 17:33
  • @user3088202 code was the wrong word used. I meant a sample of your data, e.g. apl.head().to_dict(). When you provide this we can help you quicker and time is not wasted. I don't want to sound very harsh but please look at this link for future posts: https://stackoverflow.com/help/mcve – Anton vBR Jul 27 '17 at 17:35

1 Answers1

2

Try using df.replace followed by df.dropna:

aapl = aapl.replace('null', np.nan).dropna()
cs95
  • 379,657
  • 97
  • 704
  • 746