I have this code that removes a column from a csv file. It works, but when it saves it adds decimal places (seemingly at random) to some of my values in other columns. For example, when I run the code, the value in another column changes from the original 1.815 to 1.8159999999999998, or 1.783 to 1.7830000000000001. Is there a way for me to prevent this from happening? I don't understand why it changes some values in other columns if I'm just removing column [0]. Thanks!
import pandas as pd
import os
import glob
def main():
path = os.getcwd()
csv_files = glob.glob(os.path.join(path, "*.csv"))
for f in csv_files:
df = pd.read_csv(f)
first_column = df.columns[0]
df = df.drop([first_column], axis=1)
df.to_csv(f, index=False)
main()