Reputation: 71
I have two .csv files named all_cv.csv and common_cv.csv files. First I have concat this two csv files by pandas, and then save the data into a new file named join_cv_common.csv by pandas. After that I sorted the join_cv_common.csv file by pandas as below, and stored data are stored into a new file named sorted_cv_common.csv. I want to rewrite these two functions of pandas - concat and sort by pure python (2.6 and 3.4). Can someone help me in this regards? Thank you very much.
cv = pd.read_csv('all_cv.csv')
ac = pd.read_csv('common_cv.csv')
merged = pd.concat([cv, ac])
merged.to_csv('join_cv_common.csv')
df = pd.read_csv('join_cv_common.csv')
df = df.sort(["adv_id", "conv_id"])
df.to_csv('sorted_cv_common.csv')
Upvotes: 2
Views: 874
Reputation: 196
By my knowledge it can be done by reading both the files using the file i/o after that just join and convert the string to a list after that sort the newly created list and put it in the final output csv by converting the list to a string. Following is the code implementation for that.
123.csv
1,a
2,b
4,d
456.csv
3,c
5,d
Read csv file in d1 and d2 using file open function
d = d1 + '\n' + d2
lst = d.split('\n')
data = "\n".join(sorted(lst))
Upvotes: 2