Skip to content

Instantly share code, notes, and snippets.

import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
# Create a sample dataframe
df = pd.DataFrame({
'ID': [1, 2, 3, 4],
'Col1': ['apple', 'orange', 'banana', 'pear'],
'Col2': [['apple', 'pear'], ['banana'], ['apple', 'orange'], ['banana', 'pear']]
})
import pandas as pd
df = pd.DataFrame({
'fruits': [['apple', 'banana'], ['orange', 'pear'], ['grape', 'kiwi', 'peach']]
})
# stack the dataframe
df = df['fruits'].apply(pd.Series).stack().reset_index(level=1, drop=True).to_frame('fruit')
df.index.name = 'id'
df = df.reset_index()
import pandas as pd
from ast import literal_eval
df = pd.DataFrame({
'fruits': ["['apple', 'banana']", "['orange', 'pear']", "['grape', 'kiwi', 'peach']"]
})
# convert the string representation of lists to actual lists
df['fruits'] = df['fruits'].apply(literal_eval)
@mwestwood
mwestwood / api_spec.md
Created May 5, 2023 18:15
Example of api spec

Here's an example of an API endpoint design that takes parameters:

Endpoint: /api/search Method: GET

Description: This API endpoint allows users to search for articles based on specific search criteria.

Parameters:

q (required): A string that represents the search query.

@mwestwood
mwestwood / llm_ideas.md
Last active May 8, 2023 17:34
LLM ideas

How can we use large language model in SRE to improve observability?

Large language models (LLMs) can be useful in several ways to improve observability in SRE. Here are a few examples:

  1. Log Analysis: LLMs can help in analyzing log data more efficiently by automating log parsing, anomaly detection, and log classification. SRE teams can use LLMs to analyze log data from various sources, including application logs, server logs, and network logs. By using LLMs, SREs can identify patterns and trends in log data that might be difficult to identify manually.

  2. Alert Correlation: LLMs can be used to correlate alerts generated by different monitoring tools. SRE teams can use LLMs to group related alerts based on their patterns and attributes. This can help reduce alert fatigue and enable SREs to focus on critical alerts.

  3. Incident Management: LLMs can assist in incident management by automating tasks such as incident detection, root cause analysis, and resolution. SRE teams can use LLMs to analyze monitori

import pandas as pd
import numpy as np
# Example data for last week and this week values
last_week = [0, 10, 20, 30, 40, 50, 0, 70, 80]
this_week = [10, 20, 30, 40, 50, 60, 5, 90, 100]
# Create a pandas DataFrame
df = pd.DataFrame({'Last Week': last_week, 'This Week': this_week})
import pandas as pd
import numpy as np
# Example data for last week and this week values
last_week = [0, 10, 0, 30, 40, 0]
this_week = [10, 20, 30, 40, 50, 60]
# Create a pandas DataFrame
df = pd.DataFrame({'Last Week': last_week, 'This Week': this_week})
import pandas as pd
import numpy as np
# Define the factor function
def factor(value):
if value < 10:
return 0.1
elif value < 100:
return 0.5
elif value < 1000:
import pandas as pd
import numpy as np
# Define the factor function
def factor(last_week, this_week, change):
if last_week == 0:
return 0.01
elif change < 10:
return 0.1
elif change < 100:
import pandas as pd
# Create a sample DataFrame
df = pd.DataFrame({
'Column1': ['A', 'B', 'C'],
'Column2': ['X', 'Y', 'Z'],
'Column3': ['1', '2', '3']
})
# Combine the three columns delimited by |