473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How do I create a loop for this Python code in excel?

3
I need to extract the domain for example: (http: //www.example.com/example-page, http ://test.com/test-page) from a list of websites in an excel sheet and modify that domain to give its url (example.com, test.com). I have got the code part figured put but i still need to get these commands to work on excel sheet cells in a column automatically.

Expand|Select|Wrap|Line Numbers
  1. >>> url = ("http://www.example.com")
  2. >>> domain = url.split("http://")[-1].split("/")[0]
  3. >>> print(domain)
  4.     www.example.com
  5. >>> url_2 = ("http://example.com")
  6. >>> domain_2 = url_2.split("http://")[-1].split('/')[0]
  7. >>> print(domain_2)
  8.     example.com
  9. >>> 
  10. >>> #Now to remove www. from the first one
  11. >>> 
  12. >>> domain_without_w3 = domain.split("www.")[-1]
  13. >>> print(domain_without_w3)
  14.     example.com
  15. >>> 
  16. >>> # both the commands would have to beexceuted on all the
  17. >>> # values in a coloumn to extract the domain
  18. >>> # , So here I execute the second
  19. >>> # command too on the second url.
  20. >>> 
  21. >>> domain_2_without_w3 = domain_2.split("www.")[-1]
  22. >>> print(domain_2_without_w3)
  23.     example.com
  24. >>> 
  25. >>> #Ok so how do i do these to commands on a list of urls in a column
  26. >>> # in excel automatically. That's My question.
  27. >>> #I am sorry if anything in here looks stupid or absurd
  28. >>> #I literally learned python 2 days ago.
  29.  
Jun 10 '19 #1
1 1046
Luuk
1,047 Expert 1GB
It's unclear what you want
1) do you want to create a loop in python?
2) do you want the Excel equivalent of this code?

Do you want a python solution? or an Excel solution (in which case this post needs to be moved …)
Jun 10 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: beliavsky | last post by:
How do you keep Python code properly indented as you modify it? I use an Emacs-type editor that has a Python mode, so the initial indenting is easy. If I later want to put a 'for' loop (or an 'if'...
0
by: justin worrall | last post by:
Hi,   I have a very simple python win32 example (gleaned from the O'Reilly book on Win32 programming for Python), of an Excel client with a COM server. Essentially I have three VB buttons -...
3
by: Xiao-Qin Xia | last post by:
I don't like VBA, and want to use python to work with Excel. Does anybody recommend some good documents to begin with? Many thanks, Xiao-Qin
4
by: michael.pearmain | last post by:
Hi Experts, Looking for a very quick bit on of advice on how to make some python code run. I'm a newbie to both VBA and Python, so i apologise if this is very easy but i'm about to tear my hair...
3
by: Ray | last post by:
Hi, I'm working on something with mysql and excel. I'm using python and win32com. All major function works, But I have two problems: 1. the output need to do "auto fit" to make it readable. ...
23
by: Python Maniac | last post by:
I am new to Python however I would like some feedback from those who know more about Python than I do at this time. def scrambleLine(line): s = '' for c in line: s += chr(ord(c) | 0x80)...
9
by: fahadqureshi | last post by:
Using WINXP-SP2, Python 2.3 I am trying to read an excel file and then use the numbers in the excel file to do some calculations The program reads my excel file properly but the problem comes...
1
by: chriswilliams | last post by:
This code prints output in rows like this: ****** ****** ****** How to make print in blocks like this? ***** ***** ****** ***** ***** ****** ***** ***** ***** start= int...
2
by: jld730 | last post by:
Hello All, I wrote Python code to write data to an Excel worksheet1, and also add 5 status types to worksheet2 to be used to make a dropdown list for one column in worksheet1. Could someone help...
15
by: Alex Snast | last post by:
Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i)
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.