【发布时间】:2017-08-01 23:23:52
【问题描述】:
我有一个苹果股票数据的数据框,并且 Close 列中有一些“空”字符串。我无法绘制我的数据,因为我不断收到“无法将字符串转换为...”错误。当我尝试下面的代码时,我得到一个错误'AttributeError: 'DataFrame' object has no attribute 'close_arr'。此代码基于此线程中提供的答案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()
这里是 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
我也试过了:
aapl = aapl[~aapl['Close'].str.contains("null")]
我哪里错了?
【问题讨论】:
-
向我们提供您的代码示例,例如apl.head().to_dict()
-
我的代码包含在问题中。
-
@user3088202 你的 df.head() 会有所帮助。
-
@user3088202 代码使用了错误的词。我的意思是您的数据样本,例如apl.head().to_dict()。当您提供此信息时,我们可以更快地为您提供帮助,并且不会浪费时间。我不想听起来很刺耳,但请查看此链接以获取以后的帖子:stackoverflow.com/help/mcve