- "2018-10-24 16:35:00,201.6,201.6,201.6,201.6"
- "2018-10-24 16:36:00,None,None,None,None"
- "2018-10-24 16:37:00,201.6,201.6,201.6,201.6"
- "2018-10-24 16:38:00,201.6,201.6,201.6,201.6"
- "2018-10-24 16:39:00,201.6,201.6,201.6,201.6"
- "2018-10-24 16:40:00,201.45,201.45,201.45,201.45"
- "2018-10-24 16:41:00,201.5,201.5,201.5,201.5"
- "2018-10-24 16:42:00,201.5,201.5,201.5,201.5"
- "2018-10-24 16:43:00,201.5,201.5,201.5,201.5"
- "2018-10-24 16:44:00,None,None,None,None" 我的 redis 中 zset 数据是这样的,值是一个一个的字符串 我将这些字符串取出,并进行循环遍历, 使用","分割,并放到两层嵌套的列表中 来转换为 dataframe data = [ [2018-10-24 16:42:00,201.5,201.5,201.5,201.5], [2018-10-24 16:42:00,201.5,201.5,201.5,201.5], [2018-10-24 16:42:00,201.5,201.5,201.5,201.5], ["2018-10-24 16:44:00,None,None,None,None"],] 当我使用 df = pd.DataFrame(data, dtype="float") df.fillna(method="bfill",inplace=True) 但是尝试失败了,我认为可能是因为 None 是一个字符串而不是一个空对象,我要如何进行向前补植 感谢大家 指教
2 条回复 • 2018-10-25 18:48:03 +08:00
|
1
crazycabbage 2018 年 10 月 24 日 df.replace("None", np.nan, inplace=True)
df.fillna(method="bfill") 替换后在 fill |
|
2
zcsnbb OP @crazycabbage 感谢 已解决
|
推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide