Skip to content

Instantly share code, notes, and snippets.

@viniroger
Created December 11, 2019 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniroger/9808f78967e5d432b9149484f36f39b6 to your computer and use it in GitHub Desktop.
Save viniroger/9808f78967e5d432b9149484f36f39b6 to your computer and use it in GitHub Desktop.
Create file with author, title and description
#!/usr/bin/env python3.7.5
# -*- Coding: UTF-8 -*-
# Create file with author, title and description
import pandas as pd
df_all = pd.read_csv('list1.csv')
df_desc = pd.read_csv('list2.txt', delimiter='*', header=None)
df_desc_ch = pd.read_csv('title_desc.csv')
# Loop for all musics
for n in range(0, df_all.shape[0]):
#n = 15
title = df_all.iloc[n]['titulo']
print(title)
# Escape with parenthesis
if title.find('(') != -1:
title = title.replace('(', '\(').replace(')', '\)')
## File with all descriptions
# Find row that contains string with title
value = df_desc_ch[df_desc_ch['title'].str.contains(title, case=False)]
desc = value['description']
if not desc.empty:
print(desc.iloc[0])
## File with some descriptions, but more complete
# Chek if some row contains string with title
value = df_desc[df_desc[0].str.contains(title, case=False)]
if value.empty:
#print('*not found on shorter/more complete file*')
# Update main df with description - column 2
df_all.iloc[n, 2] = desc.iloc[0]
else:
# Get next row content (description)
nx_row = value.index[0] + 1
desc2 = df_desc.iloc[nx_row][0]
print(desc2)
# Update main df with description - column 2
df_all.iloc[n, 2] = desc2 + ' ' + desc.iloc[0]
else:
print('*Without descriptions*')
print('-----------------------------------')
# Write to CSV
df_all.to_csv('final_list.csv', index=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment