LeoZhangzaolin commited on
Commit
84a6d7b
1 Parent(s): 10d0d51

Update CSV_Processing.py

Browse files
Files changed (1) hide show
  1. CSV_Processing.py +24 -0
CSV_Processing.py CHANGED
@@ -1,6 +1,7 @@
1
  #### Firstly, I read specimen data from a CSV file, merges and reformats certain columns, and then converts this data into a pandas DataFrame.
2
  #### Then, I process associated images by resizing them and saving them in a specified output directory.
3
  #### Next, I update the DataFrame with the paths to the processed images and save this enhanced dataset as a new CSV file.
 
4
 
5
  import csv
6
  import os
@@ -96,3 +97,26 @@ df.rename(columns={'image file name': 'image'}, inplace=True)
96
  # Save the DataFrame to a CSV file
97
  final_csv_path = '/Users/leozhangzaolin/Desktop/Final_GS_with_Images5.csv'
98
  df.to_csv(final_csv_path, index=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #### Firstly, I read specimen data from a CSV file, merges and reformats certain columns, and then converts this data into a pandas DataFrame.
2
  #### Then, I process associated images by resizing them and saving them in a specified output directory.
3
  #### Next, I update the DataFrame with the paths to the processed images and save this enhanced dataset as a new CSV file.
4
+ #### Finally, I upload photos to github and replace the url to corresponding names.
5
 
6
  import csv
7
  import os
 
97
  # Save the DataFrame to a CSV file
98
  final_csv_path = '/Users/leozhangzaolin/Desktop/Final_GS_with_Images5.csv'
99
  df.to_csv(final_csv_path, index=False)
100
+
101
+ # take url path to each specimens
102
+ def update_csv_with_github_links(csv_file_path, github_repo_url, branch_name):
103
+ updated_rows = []
104
+
105
+ with open(csv_file_path, mode='r') as file:
106
+ reader = csv.DictReader(file)
107
+ for row in reader:
108
+ image_name = row['image'].split('/')[-1]
109
+ row['image'] = f"{github_repo_url}/{branch_name}/{image_name}"
110
+ updated_rows.append(row)
111
+
112
+ # Write updated data back to CSV
113
+ with open(csv_file_path, mode='w', newline='') as file:
114
+ writer = csv.DictWriter(file, fieldnames=reader.fieldnames)
115
+ writer.writeheader()
116
+ writer.writerows(updated_rows)
117
+
118
+ csv_file = '/Users/leozhangzaolin/Desktop/Final_GS_with_Images5.csv'
119
+ github_repo_url = 'https://raw.githubusercontent.com/LeoZhangzaolin/photos'
120
+ branch_name = 'main'
121
+ update_csv_with_github_links(csv_file, github_repo_url, branch_name)
122
+