Hustle Hub #35

🛖 How To Use LangChain For Data Analysis (By Asking Questions)

New to Hustle Hub? Make sure to subscribe for more!

Read Time: 4 minutes

Hey hustler,

Recently I’ve been obsessed with using LangChain to analyse data because I honestly think that this would be a game changer to make data science accessible to everyone — which has always been my dream!

In today's issue, I’d like to share with you how to analyse data using LangChain (by asking questions), how you can network the right way, a very insightful article written by Sam Altman, and PandasAI!

Let’s get to it! 🚀 

🛖 What's in the hub today?

⭐️ 1 Tip

How To Use LangChain For Data Analysis (By Asking Questions)

LangChain is a framework for developing LLM applications. It enables applications that are:

  • Data-aware: connect a language model to other sources of data

  • Agentic: allow a language model to interact with its environment

In short, for our use case, we can use LangChain to connect to other data source (i.e. CSV) and use an agent to analyse the data by asking questions.

Cool right? 🤯

Luckily, LangChain already has a built-in agent to interact with a pandas DataFrame that’s optimised for question answering. It’s called Pandas Dataframe Agent.

🚀 Here’s how to use Pandas Dataframe Agent

Step 1: Import all the required libraries

from langchain.agents import create_pandas_dataframe_agent
from langchain.chat_models import ChatOpenAI
from langchain.agents.agent_types import AgentType
from langchain.llms import OpenAI
import pandas as pd

Step 2: Read a CSV file

df = pd.read_csv("titanic.csv")

Step 3: Initialise the agent

agent = create_pandas_dataframe_agent(OpenAI(temperature=0), df, verbose=True)

Step 4: Start asking questions and run the agent

agent.run("how many rows are there?")

Step 5: See the results

 > Entering new  chain...
    
    Invoking: `python_repl_ast` with `df.shape[0]`
    
    
    891There are 891 rows in the dataframe.
    
    > Finished chain.


    'There are 891 rows in the dataframe.'

This agent calls the Python agent under the hood, which will generate Python code using the selected LLM model (i.e. OpenAI).

This capability instantly unlocks a whole new opportunity to make data analysis more accessible to non-technical people as they can simply ask questions and get insights from data in seconds.

And this is just the beginning. Let’s buckle up. 🚀

🧠 I’m currently using LangChain to build an AI platform to help SMEs analyse data easily using this approach. Let me know if you want to be one of our early beta users to test out this new exciting technology!

⚠️ 1 Mistake

Remember when you were invited for a networking session for an internship or a job application? If you were an introvert just like me, the feeling sucks. 🤮

I still remember the first time I went for a networking session for my first internship application during college days, I screwed things up. I was shy to approach the company’s business associates and leaders.

Even worst, when I approached them, I sounded like I was asking for a job — just in a slightly more professional setting. Needless to say, I never heard back from them after attending the networking session (Guess they just didn’t want a weird kid in their office 😂).

I networked the wrong way

🧠 1 Learning

I’ve only learned how to network with others the right way after working in the industry for almost 5 years.

🧠 Here’s what I’ve learned:

  • Always add value first — period.

  • Networking is all about building relationships with others. And adding value is the first step to building relationships with others.

  • Never network with others expecting something in return. If you always expect something in return, you’ll never be able to connect with someone. Instead, give more, don’t ask.

  • Listen to their life stories, understand their problems, and see how you can potentially help them. When you help people, you gain trust, and trust is the foundation of building relationships.

📜 1 Article

Sam Altman is the CEO of OpenAI, and he was also previously the president of Y Combinator. 4 years ago, he wrote an article on how to become successful — which has garnered more than 1.6 million views to date.

Below are the top 5 lessons that I find very insightful and thought of sharing with you.

📚️ Here are my takeaways from the article:

  • Compound yourself

    • Most people get bogged down in linear opportunities. Be willing to let small opportunities go to focus on potential step changes.

  • Learn to think independently

    • Learn how to think from First Principles to generate new ideas.

    • Know that you can figure out what to do in situations that seem to have no solution.

  • Make it easy to take risks

    • Most people overestimate risk and underestimate reward.

    • Look for small bets you can make where you lose 1x if you’re wrong but make 100x if it works.

  • Be bold

    • Don’t be afraid to work on what you really want to work on. Follow your curiosity.

    • Things that seem exciting to you will often seem exciting to other people too.

  • You get rich by owning things

    • You don’t get rich by selling your time.

    • You get rich by owning things that increase rapidly in value, including business, real estate, natural resources, and IP.

    • The best way to make things that increase rapidly in value is by making things people want at scale.

Have you read this article? What's your thought on it?

🧰 1 Tool

PandasAI is a Python library that adds Generative AI capabilities to pandas, making dataframes conversational It means you can analyse data or generate charts by asking questions.

For example, here’s how you can ask a question:

pandas_ai = PandasAI(llm)
pandas_ai(df, prompt='Which are the 5 happiest countries?')

The code will return the following:

6            Canada
7         Australia
1    United Kingdom
3           Germany
0     United States
Name: country, dtype: object

You can also ask PandasAI to make a chart:

pandas_ai(
    df,
    "Plot the histogram of countries showing for each the gdp, using different colors for each bar",
)

And it will output the following:

Let me know how it goes after trying this tool out? 😎

🚀 Whenever you’re ready, there are 4 ways I can help you:

  1. Book a coaching call with me if you need help in the following:

How To Get Into Data Science

LinkedIn Growth, Content Strategy & Personal Branding

1:1 Mentorship & Career Guidance

Resume Review

  1. Promote your brand to 1,400+ subscribers in the data/tech space by sponsoring this newsletter.

  2. Watch my YouTube videos where I talk about data science tips, programming, and my tech life (P.S. Don’t forget to like and subscribe 💜).

  3. Follow me on LinkedIn and Twitter for more data science career insights, my mistakes and lessons learned from building a startup.

That's all for today

Thanks for reading. I hope you enjoyed today's issue. More than that, I hope it has helped you in some ways and brought you some peace of mind.

You can always write to me by simply replying to this newsletter and we can chat.

See you again next week.

- Admond

Reply

or to participate.