-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpickletocsv.py
38 lines (27 loc) · 1.51 KB
/
pickletocsv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pandas as pd
#from google.colab import files
# Loading the first pickle file
with open('diseases_names.pkl', 'rb') as f:
list1 = pd.read_pickle(f)
# Load the second pickle file
with open('skin_diseases_names.pkl', 'rb') as f:
dict2 = pd.read_pickle(f)
# Creating a dictionary from the list
dict1 = {i: v for i, v in enumerate(list1)}
print(type(dict1))
print(type(dict2))
# Merging the two dictionaries
dict1.update(dict2)
print(dict1)
# Converting the merged dictionary to a dataframe
# df = pd.DataFrame.from_dict(dict1, orient='index', columns=['#DISEASE'])
# Writing the dataframe to a CSV file
#The r before the string is used to indicate that the string is a raw string. This means that the string should be treated as a literal string, without any special characters being interpreted.
#Otherwise it will interpret it as \.. with some functionality like \n or \t
# df.to_csv(r'C:\Users\Urmil Pawar\Documents\Google Solution Challenge\diseases_names_combined.csv',index=False, index_label='INDEX')
df = pd.DataFrame.from_dict(dict1, orient='index', columns=['DISEASE'])
# Writing the dataframe to a CSV file
# The r before the string is used to indicate that the string is a raw string.
# This means that the string should be treated as a literal string, without any special characters being interpreted.
# Otherwise, it will interpret it as \.. with some functionality like \n or \t
df.to_csv(r'C:\Users\Urmil Pawar\Documents\Google Solution Challenge\diseases_names_combined.csv', index=False, header=['#DISEASE'])