Skip to content

Commit

Permalink
Python Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
linrakesh committed Jan 22, 2020
1 parent cb1baef commit 6d2c566
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 19 deletions.
8 changes: 5 additions & 3 deletions Tools/csv_to_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import csv
json = []
import json

data = []
keys = []
with open("E:/python/Tools/SampleData.csv") as csv_file:
csv_data = csv.reader(csv_file)
Expand All @@ -12,8 +14,8 @@
element = {}
for y in range(len(row)):
element[keys[y]] = row[y]
json.append(element)
data.append(element)

count = count+1

print(json)
print(json.dumps(data,))
23 changes: 23 additions & 0 deletions Tools/csv_to_xml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# python program to convert any csv file into xml file
# made by : rakesh kumar

import csv
xml = '<?xml version= "1.0" encoding="UTF-8" ?><rows>'
keys = []
with open("E:/python/Tools/SampleData.csv") as csv_file:
csv_data = csv.reader(csv_file)
count = 1
for row in csv_data:

if count == 1:
for y in row:
keys.append(y)
else:
xml += "<row>"
for y in range(len(row)):
xml += "<"+keys[y]+">"+row[y]+"</"+keys[y]+">"
xml += "</row>"
count += 1

xml += "</rows>"
print(xml)
1 change: 1 addition & 0 deletions Tools/sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?xml version= "1.0" encoding="UTF-8" ?><rows><row><Rank>1</Rank><Name>Wii Sports</Name><Platform>Wii</Platform><Year>2006</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>41.49</NA_Sales><EU_Sales>29.02</EU_Sales><JP_Sales>3.77</JP_Sales><Other_Sales>8.46</Other_Sales><Global_Sales>82.74</Global_Sales></row><row><Rank>2</Rank><Name>Super Mario Bros.</Name><Platform>NES</Platform><Year>1985</Year><Genre>Platform</Genre><Publisher>Nintendo</Publisher><NA_Sales>29.08</NA_Sales><EU_Sales>3.58</EU_Sales><JP_Sales>6.81</JP_Sales><Other_Sales>0.77</Other_Sales><Global_Sales>40.24</Global_Sales></row><row><Rank>3</Rank><Name>Mario Kart Wii</Name><Platform>Wii</Platform><Year>2008</Year><Genre>Racing</Genre><Publisher>Nintendo</Publisher><NA_Sales>15.85</NA_Sales><EU_Sales>12.88</EU_Sales><JP_Sales>3.79</JP_Sales><Other_Sales>3.31</Other_Sales><Global_Sales>35.82</Global_Sales></row><row><Rank>4</Rank><Name>Wii Sports Resort</Name><Platform>Wii</Platform><Year>2009</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>15.75</NA_Sales><EU_Sales>11.01</EU_Sales><JP_Sales>3.28</JP_Sales><Other_Sales>2.96</Other_Sales><Global_Sales>33</Global_Sales></row><row><Rank>5</Rank><Name>Pokemon Red/Pokemon Blue</Name><Platform>GB</Platform><Year>1996</Year><Genre>Role-Playing</Genre><Publisher>Nintendo</Publisher><NA_Sales>11.27</NA_Sales><EU_Sales>8.89</EU_Sales><JP_Sales>10.22</JP_Sales><Other_Sales>1</Other_Sales><Global_Sales>31.37</Global_Sales></row><row><Rank>6</Rank><Name>Tetris</Name><Platform>GB</Platform><Year>1989</Year><Genre>Puzzle</Genre><Publisher>Nintendo</Publisher><NA_Sales>23.2</NA_Sales><EU_Sales>2.26</EU_Sales><JP_Sales>4.22</JP_Sales><Other_Sales>0.58</Other_Sales><Global_Sales>30.26</Global_Sales></row><row><Rank>7</Rank><Name>New Super Mario Bros.</Name><Platform>DS</Platform><Year>2006</Year><Genre>Platform</Genre><Publisher>Nintendo</Publisher><NA_Sales>11.38</NA_Sales><EU_Sales>9.23</EU_Sales><JP_Sales>6.5</JP_Sales><Other_Sales>2.9</Other_Sales><Global_Sales>30.01</Global_Sales></row><row><Rank>8</Rank><Name>Wii Play</Name><Platform>Wii</Platform><Year>2006</Year><Genre>Misc</Genre><Publisher>Nintendo</Publisher><NA_Sales>14.03</NA_Sales><EU_Sales>9.2</EU_Sales><JP_Sales>2.93</JP_Sales><Other_Sales>2.85</Other_Sales><Global_Sales>29.02</Global_Sales></row><row><Rank>9</Rank><Name>New Super Mario Bros. Wii</Name><Platform>Wii</Platform><Year>2009</Year><Genre>Platform</Genre><Publisher>Nintendo</Publisher><NA_Sales>14.59</NA_Sales><EU_Sales>7.06</EU_Sales><JP_Sales>4.7</JP_Sales><Other_Sales>2.26</Other_Sales><Global_Sales>28.62</Global_Sales></row><row><Rank>10</Rank><Name>Duck Hunt</Name><Platform>NES</Platform><Year>1984</Year><Genre>Shooter</Genre><Publisher>Nintendo</Publisher><NA_Sales>26.93</NA_Sales><EU_Sales>0.63</EU_Sales><JP_Sales>0.28</JP_Sales><Other_Sales>0.47</Other_Sales><Global_Sales>28.31</Global_Sales></row><row><Rank>11</Rank><Name>Nintendogs</Name><Platform>DS</Platform><Year>2005</Year><Genre>Simulation</Genre><Publisher>Nintendo</Publisher><NA_Sales>9.07</NA_Sales><EU_Sales>11</EU_Sales><JP_Sales>1.93</JP_Sales><Other_Sales>2.75</Other_Sales><Global_Sales>24.76</Global_Sales></row><row><Rank>12</Rank><Name>Mario Kart DS</Name><Platform>DS</Platform><Year>2005</Year><Genre>Racing</Genre><Publisher>Nintendo</Publisher><NA_Sales>9.81</NA_Sales><EU_Sales>7.57</EU_Sales><JP_Sales>4.13</JP_Sales><Other_Sales>1.92</Other_Sales><Global_Sales>23.42</Global_Sales></row><row><Rank>13</Rank><Name>Pokemon Gold/Pokemon Silver</Name><Platform>GB</Platform><Year>1999</Year><Genre>Role-Playing</Genre><Publisher>Nintendo</Publisher><NA_Sales>9</NA_Sales><EU_Sales>6.18</EU_Sales><JP_Sales>7.2</JP_Sales><Other_Sales>0.71</Other_Sales><Global_Sales>23.1</Global_Sales></row><row><Rank>14</Rank><Name>Wii Fit</Name><Platform>Wii</Platform><Year>2007</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>8.94</NA_Sales><EU_Sales>8.03</EU_Sales><JP_Sales>3.6</JP_Sales><Other_Sales>2.15</Other_Sales><Global_Sales>22.72</Global_Sales></row><row><Rank>15</Rank><Name>Wii Fit Plus</Name><Platform>Wii</Platform><Year>2009</Year><Genre>Sports</Genre><Publisher>Nintendo</Publisher><NA_Sales>9.09</NA_Sales><EU_Sales>8.59</EU_Sales><JP_Sales>2.53</JP_Sales><Other_Sales>1.79</Other_Sales><Global_Sales>22</Global_Sales></row></rows>
3 changes: 3 additions & 0 deletions Tools/xml_beatifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
with open("E:/python/Tools/sample.xml", "r") as file:
data = file.read()
print(data)
3 changes: 3 additions & 0 deletions dictionary/dict_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

d1 = {"name": "rakesh"}
print(d1)
27 changes: 12 additions & 15 deletions fileHandling/csv_to_json_converter.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import csv
import json
with open(r'C:/Users/rakesh\Desktop/python/fileHandling/convert.csv') as csf_file:
with open('e:/python/tools/SampleData.csv') as csf_file:
csv_reader = csv.reader(csf_file)
line=0
keys=[]
jon=[]
line = 0
keys = []
jon = []
for row in csv_reader:
d = {}
if line==0:
if line == 0:
for col in row:
keys.append(col)
else:
for i in range(len(row)):
d[keys[i]]=row[i]

if(line>=1):
jon.append(d)
line+=1
#print(jon)

with open("jsonFile.json","w") as json_file:
json_file.write( json.dumps(jon,))
d[keys[i]] = row[i]

if(line >= 1):
jon.append(d)
line += 1
# print(jon)


with open("jsonFile.json", "w") as json_file:
json_file.write(json.dumps(jon,))
2 changes: 1 addition & 1 deletion jsonFile.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"album": "The White Stripes", " year": "1999", " US_peak_chart_post": " -"}, {"album": "De Stijl", " year": "2000", " US_peak_chart_post": " -"}, {"album": "White Blood Cells", " year": "20.01", " US_peak_chart_post": "61"}, {"album": "Elephant", " year": "2003", " US_peak_chart_post": "6"}, {"album": "Get Behind Me Satan", " year": "2005", " US_peak_chart_post": "3"}, {"album": "Icky Thump", " year": "2007", " US_peak_chart_post": "2"}, {"album": "Under Great White Northern Lights", " year": "2010", " US_peak_chart_post": "11"}, {"album": "Live in Mississippi", " year": "2011", " US_peak_chart_post": " -"}, {"album": "Live at the Gold Dollar", " year": "2012", " US_peak_chart_post": " -"}, {"album": "Nine Miles from the White City", " year": "2013", " US_peak_chart_post": " -"}]
[{"Rank": "1", "Name": "Wii Sports", "Platform": "Wii", "Year": "2006", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "41.49", "EU_Sales": "29.02", "JP_Sales": "3.77", "Other_Sales": "8.46", "Global_Sales": "82.74"}, {"Rank": "2", "Name": "Super Mario Bros.", "Platform": "NES", "Year": "1985", "Genre": "Platform", "Publisher": "Nintendo", "NA_Sales": "29.08", "EU_Sales": "3.58", "JP_Sales": "6.81", "Other_Sales": "0.77", "Global_Sales": "40.24"}, {"Rank": "3", "Name": "Mario Kart Wii", "Platform": "Wii", "Year": "2008", "Genre": "Racing", "Publisher": "Nintendo", "NA_Sales": "15.85", "EU_Sales": "12.88", "JP_Sales": "3.79", "Other_Sales": "3.31", "Global_Sales": "35.82"}, {"Rank": "4", "Name": "Wii Sports Resort", "Platform": "Wii", "Year": "2009", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "15.75", "EU_Sales": "11.01", "JP_Sales": "3.28", "Other_Sales": "2.96", "Global_Sales": "33"}, {"Rank": "5", "Name": "Pokemon Red/Pokemon Blue", "Platform": "GB", "Year": "1996", "Genre": "Role-Playing", "Publisher": "Nintendo", "NA_Sales": "11.27", "EU_Sales": "8.89", "JP_Sales": "10.22", "Other_Sales": "1", "Global_Sales": "31.37"}, {"Rank": "6", "Name": "Tetris", "Platform": "GB", "Year": "1989", "Genre": "Puzzle", "Publisher": "Nintendo", "NA_Sales": "23.2", "EU_Sales": "2.26", "JP_Sales": "4.22", "Other_Sales": "0.58", "Global_Sales": "30.26"}, {"Rank": "7", "Name": "New Super Mario Bros.", "Platform": "DS", "Year": "2006", "Genre": "Platform", "Publisher": "Nintendo", "NA_Sales": "11.38", "EU_Sales": "9.23", "JP_Sales": "6.5", "Other_Sales": "2.9", "Global_Sales": "30.01"}, {"Rank": "8", "Name": "Wii Play", "Platform": "Wii", "Year": "2006", "Genre": "Misc", "Publisher": "Nintendo", "NA_Sales": "14.03", "EU_Sales": "9.2", "JP_Sales": "2.93", "Other_Sales": "2.85", "Global_Sales": "29.02"}, {"Rank": "9", "Name": "New Super Mario Bros. Wii", "Platform": "Wii", "Year": "2009", "Genre": "Platform", "Publisher": "Nintendo", "NA_Sales": "14.59", "EU_Sales": "7.06", "JP_Sales": "4.7", "Other_Sales": "2.26", "Global_Sales": "28.62"}, {"Rank": "10", "Name": "Duck Hunt", "Platform": "NES", "Year": "1984", "Genre": "Shooter", "Publisher": "Nintendo", "NA_Sales": "26.93", "EU_Sales": "0.63", "JP_Sales": "0.28", "Other_Sales": "0.47", "Global_Sales": "28.31"}, {"Rank": "11", "Name": "Nintendogs", "Platform": "DS", "Year": "2005", "Genre": "Simulation", "Publisher": "Nintendo", "NA_Sales": "9.07", "EU_Sales": "11", "JP_Sales": "1.93", "Other_Sales": "2.75", "Global_Sales": "24.76"}, {"Rank": "12", "Name": "Mario Kart DS", "Platform": "DS", "Year": "2005", "Genre": "Racing", "Publisher": "Nintendo", "NA_Sales": "9.81", "EU_Sales": "7.57", "JP_Sales": "4.13", "Other_Sales": "1.92", "Global_Sales": "23.42"}, {"Rank": "13", "Name": "Pokemon Gold/Pokemon Silver", "Platform": "GB", "Year": "1999", "Genre": "Role-Playing", "Publisher": "Nintendo", "NA_Sales": "9", "EU_Sales": "6.18", "JP_Sales": "7.2", "Other_Sales": "0.71", "Global_Sales": "23.1"}, {"Rank": "14", "Name": "Wii Fit", "Platform": "Wii", "Year": "2007", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "8.94", "EU_Sales": "8.03", "JP_Sales": "3.6", "Other_Sales": "2.15", "Global_Sales": "22.72"}, {"Rank": "15", "Name": "Wii Fit Plus", "Platform": "Wii", "Year": "2009", "Genre": "Sports", "Publisher": "Nintendo", "NA_Sales": "9.09", "EU_Sales": "8.59", "JP_Sales": "2.53", "Other_Sales": "1.79", "Global_Sales": "22"}]

0 comments on commit 6d2c566

Please sign in to comment.