Skip to content

Commit eb35118

Browse files
Add files via upload
1 parent ecefcdc commit eb35118

28 files changed

+641
-0
lines changed

os/check OS.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from sys import platform
2+
if platform == "linux" or platform == "linux1" or platform == "linux2":
3+
# linux
4+
print("Your OS is linux")
5+
elif platform == "darwin":
6+
# OS X
7+
print("Your OS is MAC OS")
8+
elif platform == "win32":
9+
# Windows...
10+
print("Your OS is Windows")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import os
2+
for dirName, subdirList, fileList in os.walk(os.getcwd()):
3+
for file in fileList:
4+
print(fileList)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import pandas as pd
2+
3+
# Create a Pandas dataframe from some data.
4+
data = [10, 20, 30, 40, 50, 60]
5+
df = pd.DataFrame({'Heading': data,
6+
'Longer heading that should be wrapped': data})
7+
8+
# Create a Pandas Excel writer using XlsxWriter as the engine.
9+
writer = pd.ExcelWriter("pandas_header_format.xlsx", engine='xlsxwriter')
10+
11+
# Convert the dataframe to an XlsxWriter Excel object. Note that we turn off
12+
# the default header and skip one row to allow us to insert a user defined
13+
# header.
14+
df.to_excel(writer, sheet_name='Sheet1', startrow=1, header=False)
15+
16+
# Get the xlsxwriter workbook and worksheet objects.
17+
workbook = writer.book
18+
worksheet = writer.sheets['Sheet1']
19+
20+
# Add a header format.
21+
header_format = workbook.add_format({
22+
'bold': True,
23+
'text_wrap': True,
24+
'valign': 'top',
25+
'fg_color': '#D7E4BC',
26+
'color': '#1F497D',
27+
'border': 1})
28+
29+
# Write the column headers with the defined format.
30+
for col_num, value in enumerate(df.columns.values):
31+
worksheet.write(0, col_num + 1, value, header_format)
32+
33+
# Close the Pandas Excel writer and output the Excel file.
34+
writer.save()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from openpyxl import Workbook
2+
from openpyxl.drawing.image import Image
3+
4+
book = Workbook()
5+
sheet = book.active
6+
7+
img = Image("pic1.png")
8+
sheet['A1'] = 'This is a picture'
9+
10+
sheet.add_image(img, 'A1')
11+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
worksheet1.conditional_format('A1:J10', {'type': 'cell',
2+
'criteria': '==',
3+
'value': '"A"',
4+
'format': format1})

os/excel and csv/Temp.xlsx

6.49 KB
Binary file not shown.
Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
def set_format_tipranks_sheet(self, size_dataframe, worksheet, workbook):
2+
cell_format = workbook.add_format()
3+
cell_format.set_bg_color('#FA8072')
4+
cell_format.set_font_color('#8B0000')
5+
6+
worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell',
7+
'criteria': '<=',
8+
'value': -0.6,
9+
'format': cell_format})
10+
11+
cell_format2 = workbook.add_format()
12+
cell_format2.set_bg_color('#F79646')
13+
cell_format2.set_font_color('#FFFFFF')
14+
worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell',
15+
'criteria': 'between',
16+
'minimum': -0.3,
17+
'maximum': -0.6,
18+
'format': cell_format2})
19+
20+
cell_format5 = workbook.add_format()
21+
cell_format5.set_bg_color('#F0E68C')
22+
cell_format5.set_font_color('#755811')
23+
worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell',
24+
'criteria': 'between',
25+
'minimum': -0.0,
26+
'maximum': -0.3,
27+
'format': cell_format5})
28+
29+
cell_format3 = workbook.add_format()
30+
cell_format3.set_num_format('0.00%')
31+
worksheet.set_column('M:M', None, cell_format3)
32+
worksheet.set_column('U:U', None, cell_format3)
33+
34+
currency_format = workbook.add_format({'num_format': '$#,##0.00'})
35+
worksheet.set_column('C:I', None, currency_format)
36+
worksheet.set_column('L:L', None, currency_format)
37+
worksheet.set_column('T:T', None, currency_format)
38+
39+
date_format = workbook.add_format({'num_format': 'yyyy-mm-dd'})
40+
worksheet.set_column('AJ:AK', None, date_format)
41+
worksheet.set_column('AM:AM', None, date_format)
42+
43+
number_format = workbook.add_format({'num_format': '#,##0.00'})
44+
worksheet.set_column('J:K', None, number_format)
45+
worksheet.set_column('AI:AI', None, number_format)
46+
worksheet.set_column('N:N', None, number_format)
47+
48+
bad_cell_format = workbook.add_format()
49+
bad_cell_format.set_bg_color(self.color_format['Bad']['bg'])
50+
bad_cell_format.set_font_color(self.color_format['Bad']['font'])
51+
52+
good_cell_format = workbook.add_format()
53+
good_cell_format.set_bg_color(self.color_format['Good']['bg'])
54+
good_cell_format.set_font_color(self.color_format['Good']['font'])
55+
56+
neutral_cell_format = workbook.add_format()
57+
neutral_cell_format.set_bg_color(self.color_format['Neutral']['bg'])
58+
neutral_cell_format.set_font_color(self.color_format['Neutral']['font'])
59+
60+
warning_cell_format = workbook.add_format()
61+
warning_cell_format.set_bg_color(self.color_format['Warning']['bg'])
62+
warning_cell_format.set_font_color(self.color_format['Warning']['font'])
63+
64+
accent2_cell_format = workbook.add_format()
65+
accent2_cell_format.set_bg_color(self.color_format['Accent2_20%']['bg'])
66+
accent2_cell_format.set_font_color(self.color_format['Accent2_20%']['font'])
67+
68+
accent3_cell_format = workbook.add_format()
69+
accent3_cell_format.set_bg_color(self.color_format['Accent3_20%']['bg'])
70+
accent3_cell_format.set_font_color(self.color_format['Accent3_20%']['font'])
71+
72+
green_cell_format = workbook.add_format()
73+
green_cell_format.set_font_color('#00FF00')
74+
75+
red_cell_format = workbook.add_format()
76+
red_cell_format.set_font_color('#FF0000')
77+
78+
black_cell_format = workbook.add_format()
79+
black_cell_format.set_font_color('#000000')
80+
81+
five_level_cell_format_list = [
82+
good_cell_format, accent3_cell_format, warning_cell_format, accent2_cell_format, bad_cell_format
83+
]
84+
for i, five_level_cell_format in enumerate(five_level_cell_format_list):
85+
worksheet.conditional_format(f'O2:O{size_dataframe}', {'type': 'cell',
86+
'criteria': '==',
87+
'value': i + 1,
88+
'format': five_level_cell_format})
89+
90+
worksheet.conditional_format(f'T2:T{size_dataframe}', {'type': 'formula',
91+
'criteria': '=$U2>0',
92+
'format': green_cell_format,
93+
})
94+
worksheet.conditional_format(f'T2:T{size_dataframe}', {'type': 'formula',
95+
'criteria': '=$U2<0',
96+
'format': red_cell_format,
97+
})
98+
worksheet.conditional_format(f'T2:T{size_dataframe}', {'type': 'formula',
99+
'criteria': '=$U2="N/A"',
100+
'format': black_cell_format,
101+
})
102+
103+
worksheet.conditional_format(f'U2:U{size_dataframe}', {'type': 'cell',
104+
'criteria': '>',
105+
'value': 0,
106+
'format': green_cell_format})
107+
worksheet.conditional_format(f'U2:U{size_dataframe}', {'type': 'cell',
108+
'criteria': '<',
109+
'value': 0,
110+
'format': red_cell_format})
111+
worksheet.conditional_format(f'U2:U{size_dataframe}', {'type': 'cell',
112+
'criteria': '==',
113+
'value': '"N/A"',
114+
'format': black_cell_format})
115+
116+
green_cell_format = workbook.add_format()
117+
green_cell_format.set_font_color('#00FF00')
118+
119+
red_cell_format = workbook.add_format()
120+
red_cell_format.set_font_color('#FF0000')
121+
122+
black_cell_format = workbook.add_format()
123+
black_cell_format.set_font_color('#000000')
124+
125+
gray_cell_format = workbook.add_format()
126+
gray_cell_format.set_font_color('#808080')
127+
128+
smart_color_list = [
129+
"#C00004", "#F08C8E", "#F3A3A5", "#EECD94", "#E9D686", "#E9DE85", "#E4DE85", "#C8E0A0", "#BAD988", "#AFCC80"
130+
]
131+
132+
for i, smart_color in enumerate(smart_color_list):
133+
smart_cell_format = workbook.add_format()
134+
smart_cell_format.set_font_color(smart_color)
135+
136+
worksheet.conditional_format(f'V2:V{size_dataframe}', {'type': 'cell',
137+
'criteria': '==',
138+
'value': i + 1,
139+
'format': smart_cell_format})
140+
141+
worksheet.conditional_format(f'W2:W{size_dataframe}', {'type': 'cell',
142+
'criteria': '==',
143+
'value': '"Bullish"',
144+
'format': green_cell_format})
145+
worksheet.conditional_format(f'W2:W{size_dataframe}', {'type': 'cell',
146+
'criteria': '==',
147+
'value': '"Bearish"',
148+
'format': red_cell_format})
149+
worksheet.conditional_format(f'W2:W{size_dataframe}', {'type': 'formula',
150+
'criteria': 'AND($W2<> "Bullish", $W2 <>"Bearish")',
151+
'format': gray_cell_format})
152+
153+
worksheet.conditional_format(f'X2:X{size_dataframe}', {'type': 'cell',
154+
'criteria': '==',
155+
'value': '"Increased"',
156+
'format': green_cell_format})
157+
worksheet.conditional_format(f'X2:X{size_dataframe}', {'type': 'cell',
158+
'criteria': '==',
159+
'value': '"Decreased"',
160+
'format': red_cell_format})
161+
worksheet.conditional_format(f'X2:X{size_dataframe}', {'type': 'formula',
162+
'criteria': 'AND($W2<> "Increased", $W2 <>"Decreased")',
163+
'format': gray_cell_format})
164+
165+
worksheet.conditional_format(f'Y2:Y{size_dataframe}', {'type': 'cell',
166+
'criteria': '==',
167+
'value': '"Bought Shares"',
168+
'format': green_cell_format})
169+
worksheet.conditional_format(f'Y2:Y{size_dataframe}', {'type': 'cell',
170+
'criteria': '==',
171+
'value': '"Sold Shares"',
172+
'format': red_cell_format})
173+
worksheet.conditional_format(f'Y2:Y{size_dataframe}', {'type': 'formula',
174+
'criteria': 'AND($W2<> "Bought Shares", $W2 <>"Sold Shares")',
175+
'format': gray_cell_format})
176+
177+
tipranks_investors_list = [
178+
'"Very Positive"', '"Positive"', '"Neutral"', '"Negative"', '"Very Negative"'
179+
]
180+
181+
for i, five_level_cell_format in enumerate(five_level_cell_format_list):
182+
worksheet.conditional_format(f'Z2:Z{size_dataframe}', {'type': 'cell',
183+
'criteria': '==',
184+
'value': tipranks_investors_list[i],
185+
'format': five_level_cell_format})
186+
187+
news_sentiment_list = [
188+
'"Very Positive"', '"Positive"', '"Neutral"', '"Negative"', '"Very Negative"'
189+
]
190+
191+
for i, five_level_cell_format in enumerate(five_level_cell_format_list):
192+
worksheet.conditional_format(f'AA2:AA{size_dataframe}', {'type': 'cell',
193+
'criteria': '==',
194+
'value': news_sentiment_list[i],
195+
'format': five_level_cell_format})
196+
197+
worksheet.conditional_format(f'AB2:AB{size_dataframe}', {'type': 'cell',
198+
'criteria': '==',
199+
'value': '"Positive"',
200+
'format': green_cell_format})
201+
worksheet.conditional_format(f'AB2:AB{size_dataframe}', {'type': 'cell',
202+
'criteria': '==',
203+
'value': '"Negative"',
204+
'format': red_cell_format})
205+
worksheet.conditional_format(f'AB2:AB{size_dataframe}', {'type': 'formula',
206+
'criteria': 'AND($W2<> "Positive", $W2 <>"Negative")',
207+
'format': gray_cell_format})
208+
209+
worksheet.conditional_format(f'AC2:AC{size_dataframe}', {'type': 'cell',
210+
'criteria': '>',
211+
'value': 0,
212+
'format': green_cell_format})
213+
worksheet.conditional_format(f'AC2:AC{size_dataframe}', {'type': 'cell',
214+
'criteria': '<',
215+
'value': 0,
216+
'format': red_cell_format})
217+
worksheet.conditional_format(f'AC2:AC{size_dataframe}', {'type': 'cell',
218+
'criteria': '==',
219+
'value': '"N/A"',
220+
'format': black_cell_format})
221+
222+
worksheet.conditional_format(f'AD2:AD{size_dataframe}', {'type': 'cell',
223+
'criteria': '>',
224+
'value': 0,
225+
'format': green_cell_format})
226+
worksheet.conditional_format(f'AD2:AD{size_dataframe}', {'type': 'cell',
227+
'criteria': '<',
228+
'value': 0,
229+
'format': red_cell_format})
230+
worksheet.conditional_format(f'AD2:AD{size_dataframe}', {'type': 'cell',
231+
'criteria': '==',
232+
'value': '"N/A"',
233+
'format': black_cell_format})
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import pandas as pd
2+
3+
data_extracted = {}
4+
5+
df3 = pd.DataFrame(data_extracted)
6+
df3 = df3.fillna('N/A')
7+
8+
writer = pd.ExcelWriter("data.xlsx", engine='xlsxwriter')
9+
10+
df3.to_excel(writer, sheet_name='Sheet1', index=False)
11+
12+
# Get the xlsxwriter workbook and worksheet objects.
13+
workbook = writer.book
14+
worksheet = writer.sheets['Sheet1']
15+
16+
size_dataframe = len(df3.index) + 1
17+
18+
cell_format = workbook.add_format()
19+
cell_format.set_bg_color('#FA8072')
20+
cell_format.set_font_color('#8B0000')
21+
22+
worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell',
23+
'criteria': '<=',
24+
'value': -0.6,
25+
'format': cell_format})
26+
27+
cell_format2 = workbook.add_format()
28+
cell_format2.set_bg_color('#F79646')
29+
cell_format2.set_font_color('#FFFFFF')
30+
worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell',
31+
'criteria': 'between',
32+
'minimum': -0.3,
33+
'maximum': -0.6,
34+
'format': cell_format2})
35+
36+
cell_format5 = workbook.add_format()
37+
cell_format5.set_bg_color('#F0E68C')
38+
cell_format5.set_font_color('#755811')
39+
worksheet.conditional_format(f'M2:M{size_dataframe}', {'type': 'cell',
40+
'criteria': 'between',
41+
'minimum': -0.0,
42+
'maximum': -0.3,
43+
'format': cell_format5})
44+
45+
cell_format3 = workbook.add_format()
46+
cell_format3.set_num_format('0.00%')
47+
worksheet.set_column('M:M', None, cell_format3)
48+
49+
currency_format = workbook.add_format({'num_format': '$#,##0.00'})
50+
worksheet.set_column('C:I', None, currency_format)
51+
worksheet.set_column('L:L', None, currency_format)
52+
53+
date_format = workbook.add_format({'num_format': 'dd.mm.yyyy'})
54+
worksheet.set_column('R:S', None, date_format)
55+
worksheet.set_column('U:U', None, date_format)
56+
57+
number_format = workbook.add_format({'num_format': '#,##0.00'})
58+
worksheet.set_column('J:K', None, number_format)
59+
worksheet.set_column('O:Q', None, number_format)
60+
worksheet.set_column('V:V', None, number_format)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pandas as pd
2+
3+
ips = pd.read_csv('Result1.csv', names=['IP', 'Domain', 'Country', 'Region', 'City', 'ISP', 'ASN'],
4+
encoding='ISO-8859-1')
5+
org_file = pd.read_csv('WA_2017_append.csv', names=['First Name', 'Last Name', 'DOB', 'IP'], encoding='ISO-8859-1')
6+
7+
merged_left = pd.merge(left=org_file, right=ips, how='left', left_on='IP', right_on='IP')
8+
merged_left.to_csv('WA_2017_append(result).csv', sep=',', encoding='utf-8', header=True)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import openpyxl
2+
3+
# Read excel file
4+
input_dt = {}
5+
input_fname = 'My Excel.xlsx'
6+
7+
wb_obj = openpyxl.load_workbook(input_fname)
8+
sheet_names = wb_obj.sheetnames
9+
10+
for i, sheet_name in enumerate(sheet_names):
11+
sheet = wb_obj[sheet_name]
12+
13+
if sheet_name not in input_dt:
14+
input_dt[sheet_name] = []
15+
16+
for row_index in range(0, sheet.max_row):
17+
row = [(sheet.cell(row_index+1, col_index+1).value, sheet.cell(row_index+1, col_index+1).font) for col_index in range(sheet.max_column)]
18+
input_dt[sheet_name].append(row)

0 commit comments

Comments
 (0)