Skip to content

Instantly share code, notes, and snippets.

@richpsharp
Created October 2, 2023 21:27
Show Gist options
  • Save richpsharp/1c88c676c09e5982f4a30c7985bbb2c2 to your computer and use it in GitHub Desktop.
Save richpsharp/1c88c676c09e5982f4a30c7985bbb2c2 to your computer and use it in GitHub Desktop.
Can I guess if a decimal is a repeating decimal from a fraction?
import pandas as pd
repeating_dec_12ths = ['0833', '1666', '3333', '4166', '5833', '6666', '8333', '9166']
# 0.0833 - 1/12
# 0.1666 - 1/6
# 0.3333 - 1/3
# 0.4166 - 5/12
# 0.5833 - 7/12
# 0.6666 - 2/3
# 0.8333 - 9/12
# 0.9166 - 10/12
def formatter(x):
val = str(x).split('.')[1][:4].rstrip('0')
print(val)
n = len(val)
print([x[0:n] for x in repeating_dec_12ths])
result = val in [x[0:n] for x in repeating_dec_12ths]
print(val, result)
return val in [x[0:n] for x in repeating_dec_12ths]
table_path = "resolution.csv"
digits_of_interest = 4
# Read CSV into a DataFrame
df = pd.read_csv(table_path)
# Analyze a specific column, e.g., 'your_column'
df['repeating_dec'] = df['lon'].apply(formatter) | df['lat'].apply(formatter)
# Show the DataFrame
print(df)
df.to_csv('trunc.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment