Skip to content

Instantly share code, notes, and snippets.

@shreya-singh-tech
Created August 14, 2021 21:52
Show Gist options
  • Save shreya-singh-tech/a148c3a3b2d4553a35756a95b77ca2c2 to your computer and use it in GitHub Desktop.
Save shreya-singh-tech/a148c3a3b2d4553a35756a95b77ca2c2 to your computer and use it in GitHub Desktop.
Program to join csv
#program to combine txt.tsv and sub.tsv
import pandas as pd
# read csv data
df1 = pd.read_csv('/combinedSub_Tsv.tsv', sep = '\t')
df2 = pd.read_csv('/combinedTxt_Tsv.tsv', sep = '\t')
df1['aciks'] = df1['aciks'].astype(str)
df2_new = df2[['adsh', 'tag', 'series','class','value']].copy()
mask_df = df2_new['tag'].values == 'StrategyNarrativeTextBlock'
# new dataframe
df2_new = df2_new[mask_df]
Left_join = pd.merge(df2_new,df1,on ='adsh',how ='left')
ordered = Left_join.pop('value')
# remove column value to save as last col
Left_join['value']= ordered
Left_join.to_csv( "/Newcombined_ObjTsv_v2.tsv", index=False, sep = '\t')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment