Giter VIP home page Giter VIP logo

learn-pandas's Issues

Feature Request: Add example using the comparison operator to assign a new boolean column

Hello,

First, thank you so much for these great tutorials. There are a number of warnings regarding the usage of "just the indexing operator" for quite a while and the explanation of .loc and .iloc were tremendously helpful.

I'm writing to recommend that you add an example of assigning a new column from a boolean selection that returns a boolean series in the article on assignment. Take for example, the following:

criteria = df[‘some_col’] > sum_number
criteria.head()

0     True
1    False
2     True
4     True
6    False

Using just the assignment operator...

df['new_col'] = df['some-col'] > some_number

...works but yields the warning:

Try using .loc[row_indexer,col_indexer] = value instead

The closest example I've found in your article is this one:

last_name = pd.Series(data=['Smith', 'Jones', 'Williams', 'Green', 'Brown', 'Simpson', 'Peters'],
                      index=['Tom', 'Niko', 'Penelope', 'Aria', 'Sofia', 'Dean', 'Zach'])
last_name
df['last_name'] = last_name

However, at least in Pandas 0.19.2, this will still yield the same error. After searching around a bit I found this stack overflow discussion which states that after Pandas 0.16.0, the best way to do this is to use the assign function in the following manner:

criteria = df[‘some_col’] > sum_number
df_three.assign(new_col_name = criteria) #note: no quotes on new_col_name

Which seems to work well for me.

Alternatively, I suppose you can simply add which version the tutorial was written under.

Thanks again for this wonderful guide!

Typo in 02 Boolean Indexing.ipynb

Thank you for the tutorials!
I think there's a typo in Exercise 13 of 02 Boolean Indexing.ipynb: it reads "Get the same exact result as exercise 11", but probably should read "Get the same exact result as exercise 12".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.