If you want to master data science in Python, you need to learn Pandas method chaining.



[thread: 1/14]

#data #datascience #Python
[2/14]

Pandas method chains enable you to combine together several individual Pandas techniques in complex ways.
[3/14]

When most people do this, they do it with very long chains of techniques, *all on a single line*.

These are hard to read and hard to debug.

They get more challenging the longer they get.
[4/14]

There's a better way though.

If you use a special syntax, you can put the Pandas methods on separate lines.

#data #datascience #Python
[5/14]

To do this, you need to enclose the entire expression inside of parenthesis.

You need to have an "open" parenthesis before the dataframe name.

And you need a "close" parenthesis after the last method.
[6/14]

This seems strange to many Python users, but it is extremely powerful.
[7/14]

To understand, let's look at a revised version of the code I showed earlier.

Here, we're using two different Pandas methods in series...

But on separate lines.
[8/14]

When we write the code this way, the code becomes *dramatically* easier to read and also debug.

It's easier to debug, because we can simply comment out methods that we don't want to use.

#data #datascience #Python
[9/14]

This technique really shows its power when you use more than 2 or 3 methods.

You can chain together many Pandas methods to perform complex data manipulations.
[10/14]

Here's an example of Pandas method chaining with 3 methods:
[11/14]

And here's an example of Pandas method chaining with 6 methods.

This is a highly complex data manipulation, and we've done it in a single block of code.

#data #datascience #Python
[12/14]

As you probably know, if you want to master data science, you need to master data wrangling.

And if you want to master data wrangling in Python, you need to master this technique.
[13/14]

The Pandas method chaining technique is very powerful, and it enables you to do complex data wrangling and complex data analysis it a much more streamlined way.
[14/14]

To learn more about data science and data wrangling in Python, follow me here: @Josh_Ebner

Every day, I post tutorials and tips on how to master data science in R and Python.

#data #datascience #Rstats #Python

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Joshua Ebner

Joshua Ebner Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Josh_Ebner

31 Aug
The big thing that I'd change here is the color palette.

This color palette is hard to interpret and frankly, just look a little ugly.

#datascience #DataVisualization

[1/11]
[2/11]

The fix here is pretty simple.

The data are sequential in nature. There's a low and a high.

When you have sequential data, you should almost always look at sequential color palettes.

[3/11]

More specifically:

For sequential data, your go-to palettes should almost always be perceptually uniform sequential palettes like viridis or magma.

Read 11 tweets
30 Aug
If you want to create great data visualizations, you need to understand color palettes.

Here are a few quick tips:

[1/n]

#datascience #datavisualization #Python #rstats
[2/n]

For data that has a sequential ordering (i.e., low to high), you should use sequential color scales.

matplotlib.org/stable/tutoria…

#Python #matplotlib Image
[3/n]

Sequential color scales incrementally change saturation or lightness.

For example, this is a red-sequential color palette: Image
Read 24 tweets
28 Aug
@JoshuaSteinman My understanding based on some research last year and beyond, is that these are deep-water.

... and there's possibly more ports with shallow depth
@JoshuaSteinman For example, @PeterZeihan wrote that Texas has "thirteen world-class deepwater ports"

amzn.to/3BihKN6
@JoshuaSteinman @PeterZeihan Army Corps of Engineers puts it at "15 deep draft ports" and "13 shallow draft ports" along the TX coast.

swd.usace.army.mil/About/Texas-Po…
Read 5 tweets
28 Aug
@JoshuaSteinman Regarding: An American Shenzhen

There's a *lot* of good ports along the Texas coast, and I think much of it under-used.

Great for logistics into the American Heartland, and also into LatAm and Mexico.
@JoshuaSteinman The Texas/Mexico combo provides a unique mix of high-skill, medium-skill, and low-skill labor.

High end design and MFG in TX, lower skill MFG and assembly in MX.
@JoshuaSteinman Also great energy resources in TX (although nuclear would augment).
Read 5 tweets
26 Aug
How to Add New Variables to a Python Dataframe

sharpsightlabs.com/blog/pandas-as…

[Thread: 1/9]

#data #datascience #Python Image
[2/9]

There are several ways to add a variable to a Python dataframe ...

But my preferred way is the Pandas "assign" method.
[3/9]

The Pandas assign method has fairly simple syntax.

You can use the technique to add a single new variable like this: Image
Read 9 tweets
3 May 20
If there's a large migration of talented people from SF and NYC to Austin, Austin has a shot at being the next Silicon Valley.

#SF #NewYork #SiliconValley #technology #Austin #Texas

(Thread)
2/n

Remember: Texas actually has a long tradition of innovation.

For example, the integrated circuit was invented at Texas Instruments.

en.wikipedia.org/wiki/Texas_Ins…

#technology #tech #Texas ImageImage
3/n

More recently, Amazon, Facebook, Google, and Apple have announced major campuses in Austin.

Google is building a new riverside building, and Facebook already has one.

austin.curbed.com/2019/4/2/18291… ImageImage
Read 15 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(