added script to prepare csv source file
This commit is contained in:
@@ -0,0 +1,34 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# prepare csv path
|
||||||
|
input_path = Path(__file__).parent / 'images_mm.csv'
|
||||||
|
assert input_path.exists()
|
||||||
|
# load in csv
|
||||||
|
df = pd.read_csv(
|
||||||
|
input_path,
|
||||||
|
delimiter=';',
|
||||||
|
header=None,
|
||||||
|
names=['name', 'url'],
|
||||||
|
)
|
||||||
|
# remove last letter from names
|
||||||
|
df['name'] = df['name'].str[:-1]
|
||||||
|
# remove rows with duplicate names
|
||||||
|
df.drop_duplicates(subset='name', inplace=True)
|
||||||
|
# reset index to look more nice
|
||||||
|
df.reset_index(drop=True, inplace=True)
|
||||||
|
# remove query from urls
|
||||||
|
pattern = r'(\?img_.+)'
|
||||||
|
df['url'] = df['url'].str.replace(
|
||||||
|
pat=pattern,
|
||||||
|
repl='',
|
||||||
|
regex=True,
|
||||||
|
)
|
||||||
|
# save df to file
|
||||||
|
output_path = input_path.parent / 'sources.csv'
|
||||||
|
df.to_csv(output_path, index=False)
|
||||||
Reference in New Issue
Block a user