OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to make a list from array [closed]

  • Thread starter Thread starter Pol02R
  • Start date Start date
P

Pol02R

Guest
I have an Excel file and need to get data from rows and columns and make a JSON text from it. I use openpyxl.

Column AColumn B
City 1
City 210.500

Let's say that's my Excel file.

My goal is to save this data as JSON with the following format:

Code:
[{"City 1": None, "City 2": 10500}]

What I've tried so far:

Code:
wb = load_workbook('C:\\smth\\form.xlsx', data_only=True)
ws1 = wb['page']

ws1.delete_rows(idx=1, amount=7) #deleted first rows 'cause I don't need them

sheet = ws1
for i in range(10, 19):
        city = sheet.cell(row=i, column=1).value
        valuecity = sheet.cell(row=i, column=2).value
        
        a = [city, valuecity]

        xs = [a]
        s = ''.join(str(x) for x in xs)

I know that it may be wrong and not suitable for my request, I just don't know how to get the data I need another way.

So after converting it to list it was like that:

Code:
['City 1', None]
['City 2', '10500']

And when I convert it to a string and let's say want to remove the last character I get that:

Code:
['City 1', None
['City 2', '10500'

Though I want just an ordinary list and an ordinary string. Can anyone help? It looks like Python reads it as two different strings in one variable.
<p>I have an Excel file and need to get data from rows and columns and make a JSON text from it. I use openpyxl.</p>
<div class="s-table-container"><table class="s-table">
<thead>
<tr>
<th>Column A</th>
<th>Column B</th>
</tr>
</thead>
<tbody>
<tr>
<td>City 1</td>
<td></td>
</tr>
<tr>
<td>City 2</td>
<td>10.500</td>
</tr>
</tbody>
</table></div>
<p>Let's say that's my Excel file.</p>
<p>My goal is to save this data as JSON with the following format:</p>
<pre><code>[{"City 1": None, "City 2": 10500}]
</code></pre>
<p>What I've tried so far:</p>
<pre><code>wb = load_workbook('C:\\smth\\form.xlsx', data_only=True)
ws1 = wb['page']

ws1.delete_rows(idx=1, amount=7) #deleted first rows 'cause I don't need them

sheet = ws1
for i in range(10, 19):
city = sheet.cell(row=i, column=1).value
valuecity = sheet.cell(row=i, column=2).value

a = [city, valuecity]

xs = [a]
s = ''.join(str(x) for x in xs)
</code></pre>
<p>I know that it may be wrong and not suitable for my request, I just don't know how to get the data I need another way.</p>
<p>So after converting it to list it was like that:</p>
<pre><code>['City 1', None]
['City 2', '10500']
</code></pre>
<p>And when I convert it to a string and let's say want to remove the last character I get that:</p>
<pre><code>['City 1', None
['City 2', '10500'
</code></pre>
<p>Though I want just an ordinary list and an ordinary string. Can anyone help? It looks like Python reads it as two different strings in one variable.</p>
 
Top