Manipulating csv files in python
Now that I am only downloading data on 5,000 cryptos daily from CoinGecko, I needed to subset my other files so that they only contained 5,000 cryptos. Here is the code, I used to manage the files.
Python Code
import os
import glob
import csv
import pandas as pd
print(os.getcwd())
os.listdir()
path_dir = 'CGdata_s3_AugSeptOctNovDec_2022_old'
new_dir = "Cryptos_5000_Data/"
all_files = os.listdir(path_dir)
csv_files = list(filter(lambda f: f.endswith('.csv'), all_files))
for i in csv_files:
file_path = path_dir + "/" + i
data = pd.read_csv(file_path, nrows = 5000)
path_file = path_dir + "/" + new_dir + i
data.to_csv(path_file, index = False )
Comments
Post a Comment