avatarEsteban Thilliez

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

5582

Abstract

alcoholics, for reasons yet obscure, have lost the power of choice in drink. Our so-called will power becomes practically nonexistent. We are unable, at certain times, to bring into our consciousness with sufficient force the memory of the suffering and humiliation of even a week or a month ago. We are without defense against the first drink.</p></blockquote><blockquote id="b97c"><p>~ The Big Book, page 24.</p></blockquote><p id="2733">I mumbled something about doing more therapy sessions to stay in touch with my baseline feelings, but my new sponsor was having none of it.</p><p id="e1c9">‘This isn’t an emotional issue!’ he said, cutting in. ‘This is a memory issue that no amount of therapy you chose to throw money at will solve.’</p><p id="1800">He even suggested that the mental blank spot could be similar to a form of amnesia or dementia that science hasn’t picked up on yet.</p><p id="4ad6">‘But why hasn’t science picked up on it?’ I asked, holding the phone tightly.</p><p id="26fb">‘Probably because this blank spot only happens at certain times. Most of the time, it lays dormant.’ he replied before warning,</p><p id="337a">‘And unfortunately, this dormancy feature gives us an illusion of power. We think we’ve got sobriety now because our memory and willpower function normally again. Until, the condition randomly comes back online, and we relapse, leaving us totally baffled as to why it happened.’</p><p id="a3e9">My new sponsor sighed deeply.</p><p id="f455">‘It’s heartbreaking,’ he said softly. ‘Especially if you’ve relapsed after being multiple years clean. But it is sadly needed to show you that you are genuinely powerless, regardless of how much you desire and want to be sober.’</p><p id="969d">My head was spinning. Every sentence felt like the jolt of an electric cattle prod.</p><p id="8e0a">Later that day, I looked back at my recent relapses. I found no real conscious memory of consequences before any of them.</p><p id="352f">It appeared relapse was happening to me, not by me.</p><blockquote id="8aba"><p>As soon as I regained my ability to think, I went carefully over that evening in Washington. Not only had I been off guard, I had made no fight whatever against the first drink. This time I had not thought of the consequences at all. I had commenced to drink as carelessly as though the cocktails were ginger ale. I now remembered what my alcoholic friends had told me, how they prophesied that if I had an alcoholic mind, the time and place would come — I would drink again. They had said that though I did raise a defense, it would one day give way before some trivial reason for having a drink. Well, just that did happen and more, for what I had learned of alcoholism did not occur to me at all. I knew from that moment that I had an alcoholic mind. I saw that will power and self-knowledge would not help in those strange mental blank spots. I had never been able to understand people who said that a problem had them hopelessly defeated. I knew then. It was a crushing blow.</p></blockquote><blockquote id="93f7"><p>~ The Big Book, page 41.</p></blockquote><figure id="7922"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*n4r4HuNFWSnCD_WU"><figcaption>Photo by <a href="https://unsplash.com/@alicealinari?utm_source=medium&amp;utm_medium=referral">Alice Alinari</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h2 id="287c">A Belief That It Will All Be Alright.</h2><p id="baea">Sadly, the ‘blank spot’ wasn’t all that was happening.</p><p id="7c3e">My new sponsor later explained that something else was happening in my mind, a kind of twisting of my thinking that I couldn’t see either.</p><p id="02a0">This is the other main feature of the relapse condition.</p><p id="da70">The Big Book explains it as follows:</p><blockquote id="f067"><p>But there was always the curious mental phenomenon that parallel with our sound reasoning, there inevitably ran some insanely trivial excuse for taking the first drink. Our sound reasoning failed to hold us in check. The insane idea won out.</p></blockquote><blockquote id="4ad8"><p>~ The Big Book, page 37.</p></blockquote><p id="da58">Anytime the ‘good idea’ of relapsing suddenly popped into my head, part of me would start to minimise the lunacy of this thought.</p><p id="e2c7">I would begin to rationalise this catastrophic idea with excuses and reasons why it would be, in fact, okay to relapse despite being in recovery.</p><p id="432a">No matter how insignificant and non-sensical those reasons were, they quickly became plausible and seemingly rational.</p><p id="6997">At the same time, the urge to want to relapse would start to surge.</p><p id="cdc4">A fear of missing out would relentlessly come crashing in like waves rolling in and out of my consciousness.</p><p id="b225">Thoughts and narratives of why it would be okay this time would dominate my thinking.</p><p id="fe2d">Finally, a tidal wave of justification would smother me into deep unconsciousness.</p><p id="c65b">Convinced of my rationale, I would carry out my plan, only to revert back to type and do everything I said I wouldn’t do, and again, find myself powerless to stop once I started.</p><p id="34a2">This twisted thinking was nothing more than a lie, but I believed the lie and didn’t see the flaw in the logic in light of my track record with partying.</p><p id="888a">To any average person, this kind of thinking and decision-making would be termed irrational, unsound, or even insa

Options

ne.</p><p id="d880">The Big Book calls this thinking an <i>‘obsession to beat the game’</i>.</p><p id="9087">Whether it’s a vague idea that this time it would be different, that I would do it differently and party like a gentleman.</p><p id="b075">Or the well-loved excuse that this will be my last relapse. After this final time, I’ll be done for good. I’ll get on with my life.</p><p id="be67">But, it never was different and that last time never did happen.</p><p id="149d">My new sponsor would remind me often,</p><p id="a62b" type="7">‘You aren’t changing your mind when you’ve decided to give in and party; your mind has been changed for you.’</p><h2 id="4c19">It Centers In Our Minds</h2><p id="f0e7">Of course, there is a body element for the addict.</p><p id="86b6">Naturally, as a consequence of the constant extreme usage of powerfully addictive substances and processes that are designed by their very nature to make you want more and more, addicts have developed a sky-high tolerance.</p><p id="2d70">But there’s this annihilation approach to our acting out and using once we start, which the Big Book describes as the <i>‘phenomenon of craving’</i>.</p><p id="01c2">In the Doctor’s opinion in the Big Book, Dr. Silkworth calls the phenomenon of craving an ‘allergy’, but my new sponsor wasn’t too keen on that idea.</p><p id="10af" type="7">‘If it’s an allergy, then why doesn’t the phenomenon of craving happen every time?’</p><p id="ae75">Regardless of whether it is an allergy, the body part becomes irrelevant, as most people with a severe peanut allergy don’t tend to keep repeating the total lost cause of trying to have another peanut to see if they will react differently.</p><p id="2e48">They don’t touch or go anywhere near peanuts because they remember how terrible it was last time.</p><p id="436a">Once or twice is enough.</p><p id="3796">Not so with the real addict because of the first two features of the disease; they will not only be back gorging on peanuts, but they will eventually take up residence in a peanut factory.</p><blockquote id="e3f6"><p>There is a complete failure of the kind of defence that keeps one from putting his hand on a hot stove. The alcoholic may say to himself in the most casual way, “It won’t burn me this time, so here’s how!” Or perhaps he doesn’t think at all.</p></blockquote><blockquote id="d5e6"><p>~ The Big Book, page 24.</p></blockquote><p id="5cb9">That’s why the Big Book says the real problem ‘centers in our mind’, not our bodies.</p><p id="22d4">‘What will happen now,’ my new sponsor forewarned, ‘as the relapses get worse, the time between them will get shorter and shorter.’</p><p id="6f0b">This condition is progressive.</p><p id="e8f1">Therefore, the blanking and twisting will naturally grow in scope and reach until you can no longer differentiate the true from the false.</p><h2 id="869b">Turning To Something Else</h2><p id="922a">If you believe in the disease concept of addiction, that this is a disease, a fatal illness precisely like any other life-threatening condition, then you have it for life.</p><p id="a2d8">There is <b>nothing </b>you can do to change that.</p><p id="d5f6">If you constantly can’t remember why or how you relapsed despite your honest desire not to.</p><p id="9aaf">Or if you continually relapse, believing some trivial reason or silly excuse to relapse while dismissing the genuine consequences, then you are a real addict.</p><p id="a47a">You have this relapse condition.</p><p id="840d">You <b>crossed a threshold </b>where, at certain times, your inability to use reasoning and rational thinking won’t even register for you.</p><p id="d8c6">The tragic truth is that once that threshold has been crossed, you have <b>no choice</b> but to relapse.</p><p id="0564">A compromised part of your brain will always fire the thought of using or acting out. That will never change. It’s wired like that for life.</p><p id="5fb0">There is no cure.</p><p id="fcca">Even this information won’t save you, as at certain times, you won’t be able to recall any of it when it matters.</p><p id="7fc5">So, let go of trying to change that.</p><p id="59f9">Let go of any old ideas around fighting it and instead get out of the way and <b>trust in something else</b>.</p><p id="b722">After all, that’s all you’ve got.</p><p id="5065">There’s nothing you or anyone else can do to stop this relapse condition.</p><p id="d1dd">But there’s everything you can do about everything else.</p><p id="5e51">There’s everything you can do about building a <b>spiritual dimension</b> to your life, by giving back, helping others, living in genuine faith and trusting in something greater than you.</p><p id="3096">There’s everything you can do to improve your awareness and intuition, raise your consciousness and develop another part of your brain.</p><p id="7598">And let this part of your brain grow bigger and stronger than that addictive part so that it can embrace and look after that compromised part.</p><p id="d2e3">Just like a bigger and wiser older sibling can care for and comfort a much younger upset sibling by giving that stressed child a big hug.</p><p id="da93">There’s everything you can do about deciding to take on a new attitude, direction, and way of life that will keep this condition dormant one day at a time.</p><p id="e415">If this article speaks to you, please follow, share and subscribe to me for more.</p><p id="fc50">Click <a href="https://twitter.com/TheDarrenJames">here</a> to follow me on <a href="https://twitter.com/TheDarrenJames">X</a>.</p></article></body>

Pandas Basics — 2. Grouping, Aggregating, Analyzing

Photo by UX Indonesia on Unsplash

This article follows Pandas Basics — Part. 1. Today, we’ll focus on topics more related to data manipulation. We’ll explore advanced topics in Pandas such as merging and joining DataFrames, handling categorical data, etc…

Let’s get started!

Grouping and Aggregation

Grouping and aggregation are essential techniques in any data analysis pipeline, and Pandas provides several functions and methods to perform these operations with ease.

First, the groupbyfunction is one of the most powerful and flexible tools in Pandas. It allows you to split a DataFrame into groups based on one or more columns, and apply a function to each group.

For example, let’s say we have a dataset of sales data for a store, and we want to calculate the total sales for each store location. We can use the groupbyfunction to split the data by store location, and then apply the sum function to each group:

import pandas as pd

df = pd.read_csv('sales_data.csv')

# Group data by store location and sum sales
df_grouped = df.groupby('location').sum()

print(df_grouped)

This will output a new DataFrame containing the total sales for each store location:

location
New York       89000
San Francisco  80000
Toronto        70000
Name: sales, dtype: int64

Another useful function for grouping and aggregation is pivot_table. This function allows you to create a new DataFrame by pivoting the columns of an existing DataFrame.

For example, let’s say we have a dataset of sales data for a store, and we want to create a new table showing the total sales by store location and product category. We can use the pivot_tablefunction to do this:

import pandas as pd

df = pd.read_csv('sales_data.csv')

# Create a pivot table showing total sales by location and product category
df_pivot = df.pivot_table(index='location', columns='category', values='sales', aggfunc=sum)

print(df_pivot)

This will output a new pivot table showing the total sales by location and product category:

category       Furniture  Office Supplies  Technology
location                                        
New York         35000.0           22000.0     32000.0
San Francisco    30000.0           25000.0     25000.0
Toronto          20000.0           10000.0     10000.0

In addition to the built-in functions, you can also apply your own custom functions to groups of data in Pandas.

For example, let’s say we have a dataset of employee data, and we want to calculate the average salary by department. We can use the apply function to apply a custom function to each group:

import pandas as pd

df = pd.read_csv('employee_data.csv')

# Define a custom function to calculate the average salary
def avg_salary(group):
  return group['salary'].mean()

# Group data by department and apply the custom function
df_grouped = df.groupby('department').apply(avg_salary)

print(df_grouped)

This will output a new Series containing the average salary for each department:

department
HR             50000.0
IT             60000.0
Marketing      75000.0
Sales          65000.0
dtype: float64

Time Series Analysis

Time series data is a type of data that is collected over a period of time, and is often used in fields such as finance, economics, and meteorology. In Pandas, time series data is typically stored in a DataFrame with a DatetimeIndex.

One of the key techniques for working with time series data in Pandas is resampling. Resampling is the process of downsampling or upsampling a time series to a different frequency. For example, you might want to resample a daily time series to a monthly frequency in order to compare the data at a higher level.

To resample a time series in Pandas, you can use the resample function, which is available on the DataFrame object. Here is an example of how to resample a daily time series to a monthly frequency:

import pandas as pd

df = pd.read_csv('time_series_data.csv', index_col='date', parse_dates=True)

# Resample to monthly frequency
df_monthly = df.resample('M').mean()

print(df_monthly)

This will output a new time series with the data resampled to a monthly frequency. You can also use the resample function to apply other functions to the data, such as sum, min, or max.

Another useful technique for working with time series data is shifting. Shifting is the process of moving the data forward or backward in time by a certain number of periods. For example, you might want to shift a time series forward by one month in order to compare the data to the previous period.

To shift a time series in Pandas, you can use the shift function, which is available on the DataFrame object. Here is an example of how to shift a monthly time series forward by one month:

import pandas as pd

df = pd.read_csv('time_series_data.csv', index_col='date', parse_dates=True)

# Shift the data forward by one month
df_shifted = df.shift(periods=1, freq='M')

print(df_shifted)

This will output a new time series with the data shifted forward by one month. You can also use the shift function to shift the data backward by specifying a negative value for the periods parameter.

Merging and Joining

Merging and joining DataFrames is a common task in data analysis, and Pandas provides a number of functions and methods to perform these operations with ease.

The main difference between merging and joining is the way in which the data is combined. In a merge, the data is combined based on common columns or keys. In a join, the data is combined based on the index of the DataFrames.

To merge two DataFrames in Pandas, you can use the mergefunction, which is available on the DataFrame object. Here is an example of how to merge two DataFrames based on a common column:

import pandas as pd

df1 = pd.read_csv('data1.csv')
df2 = pd.read_csv('data2.csv')

# Merge the DataFrames on the 'id' column
df_merged = pd.merge(df1, df2, on='id')

print(df_merged)

This will output a new DataFrame containing the merged data from both DataFrames.

# Input

data1.csv:
id,value1,value2
1,10,20
2,15,25
3,20,30

data2.csv:
id,value3,value4
1,30,40
2,35,45
3,40,50

# Output

id,value1,value2,value3,value4
1,10,20,30,40
2,15,25,35,45
3,20,30,40,50

You can also specify different merge methods, such as inner, outer, or left, to control how the data is combined.

To join two DataFrames in Pandas, you can use the joinfunction, which is available on the DataFrame object. Here is an example of how to join two DataFrames based on their index:

import pandas as pd

df1 = pd.read_csv('data1.csv', index_col='id')
df2 = pd.read_csv('data2.csv', index_col='id')

# Join the DataFrames
df_joined = df1.join(df2)

print(df_joined)

This will output a new DataFrames containing the joined data from both DataFrames.

# Input

data1.csv:
id,value1,value2
1,10,20
2,15,25
3,20,30

data2.csv:
value3,value4,id
30,40,1
35,45,2
40,50,3

# Output

id,value1,value2,value3,value4
1,10,20,30,40
2,15,25,35,45
3,20,30,40,50

You can also specify different join types, such as inner, outer, or left, to control how the data is combined.

Another advanced technique in Pandas is concatenation, which is the process of combining multiple DataFrames into a single DataFrames. To concatenate DataFrames in Pandas, you can use the concatfunction. Here is an example of how to concatenate two DataFrames vertically (i.e., adding rows to the DataFrame):

import pandas as pd

df1 = pd.read_csv('data1.csv')
df2 = pd.read_csv('data2.csv')

# Concatenate the DataFrames
df_concat = pd.concat([df1, df2])

print(df_concat)

This will output a new DataFrame containing the concatenated data from both DataFrames.

# Input

data1.csv:
id,value1,value2
1,10,20
2,15,25
3,20,30

data2.csv:
id,value3,value4
4,30,40
5,35,45
6,40,50

# Output

id,value1,value2,value3,value4
1,10,20,NaN,NaN
2,15,25,NaN,NaN
3,20,30,NaN,NaN
4,NaN,NaN,30,40
5,NaN,NaN,35,45
6,NaN,NaN,40,50

You can also specify different axis values, such as ‘columns’, to concatenate the DataFrames horizontally (i.e., adding columns to the DataFrame).

Pandas in Practice

Now that you have learned the basics of Pandas, it’s time to put your skills into practice.

One common task in data analysis is cleaning and preparing data for further analysis. In Pandas, you can use a number of functions and methods to handle missing data, remove duplicates, and transform the data into the desired format. For example, let’s say we have a dataset of customer data, and we want to clean and prepare the data for further analysis. Here is some code that demonstrates how to do this:

import pandas as pd

df = pd.read_csv('customer_data.csv')

# Remove rows with missing data
df.dropna(inplace=True)

# Remove duplicates
df.drop_duplicates(inplace=True)

# Transform the data
df['customer_id'] = df['customer_id'].astype(str)
df['signup_date'] = pd.to_datetime(df['signup_date'])

print(df)

Another common task in data analysis is visualizing data. In Pandas, you can use the plot function, which is available on the DataFrame object, to create a variety of plots. You need Matplotlib to plot DataFrames.

For example, let’s say we have a dataset of sales data, and we want to visualize the data using a line plot. Here is some code that demonstrates how to do this:

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('sales_data.csv', index_col='date', parse_dates=True)

# Create a line plot
df.plot(kind='line')

# Show the plot
plt.show()

This will create a line plot showing the sales data over time. You can also use the plot function to create other types of plots, such as bar plots, scatter plots, and pie charts.

Now it’s your turn to try out these techniques in practice. Here are some hands-on exercises for you to complete:

  1. Load a dataset of your choice and clean and prepare the data using the techniques demonstrated above.
  2. Visualize the data using the plot function and try out different plot types.
  3. Use the groupbyand pivot_tablefunctions to analyze and summarize the data.
  4. Try applying custom functions to groups of data using the apply function.

Final Note

Now you are ready to take it to the next level and learn more complex things, such as developing solutions for supervised, unsupervised learning, etc…

I’ll soon write a series to learn machine learning, so be sure to follow me to don’t miss it!

To explore more of my Python stories, click here! You can also access all my content by checking this page.

If you liked the story, don’t forget to clap, comment, and maybe follow me if you want to explore more of my content :)

You can also subscribe to me via email to be notified every time I publish a new story, just click here!

If you’re not subscribed to Medium yet and wish to support me or get access to all my stories, you can use my link:

Data Science
Data Analysis
Pandas
Python
Programming
Recommended from ReadMedium
avatarJYOTI PRAKASH DEY
14 pandas tricks you MUST know

7 min read