attribute error: unable to remove columns with low std

16 views
Skip to first unread message

Vaibhav Dixit

unread,
Mar 2, 2019, 8:42:46 AM3/2/19
to Project Jupyter
Dear Jupyter users and experts,
I am new to using Jupyter notebook installed via "anaconda navigator".
For my ML needs, I need to preprocess data in CSV file i.e. remove columns with < 5% std (and remove rows for which > 50% features are zero valued etc).
I tried the std condition with the following code, but it gives the following error.
I couldn't find an easy solution in manuals and with google either.
Can you please suggest me on a possible fix for this?
thanks.

Code:
----------
import pandas as pd
import numpy as np
#df = pd.DataFrame()
with open('test.csv', 'r', encoding="ascii", errors="surrogateescape") as f:
    data = f.read()
#f = pd.read_csv('test.csv')
    df = pd.DataFrame(f)

#    pd.std(axis=10)
    rmcols = pd.drop(pd.std()[(pd.std() == 0)].index, axis=1)
    rmcols.to_csv('new.csv')
-------------

Error:
-------------
AttributeError                            Traceback (most recent call last)
<ipython-input-22-76d08e00951a> in <module>
      8 
      9 #    pd.std(axis=10)
---> 10     rmcols = pd.drop(pd.std()[(pd.std() == 0)].index, axis=1)
     11     rmcols.to_csv('new.csv')

AttributeError: module 'pandas' has no attribute 'drop'
------------

Chris Holdgraf

unread,
Mar 2, 2019, 4:57:52 PM3/2/19
to jup...@googlegroups.com
Hello!

I'd recommend checking out the Pandas documention (https://pandas.pydata.org/pandas-docs/stable/) for ideas of how to use it. Jupyter makes it possible to use interactive tools like Pandas, but it doesn't create Pandas itself so this isn't the best place to ask for support (I'd bet Pandas has a mailing list though). Another good option is the "scipy-lectures" website which has several helpful modules (and I think covers Pandas) http://scipy-lectures.org/intro/

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/a798b950-0a3a-4b80-8ef7-7ba91593f893%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages