473,667 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

3 New Member
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 1058
Luuk
1,047 Recognized Expert Top Contributor
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
2597
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' statement) around a bunch of code, I find myself going through the body of the loop, manually re-indenting to keep the nested loops correct. There should be a better way. I think that having a 'for' loop end with a matching 'next' statement,...
0
1650
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 - start_server, stop_server and test_server. The first two do the obvious, the last takes inputs from two cells in the excel sheets, then passes them to the python server which adds them together and returns the result an Excel message dialog.  
3
3433
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
7947
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 out after googling for the last 3 days. I have written a large python script which inside of it creates an Excel table, the name of this file and how many objects can change for each project i run.
3
6280
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. I tried to call "xlApp.Columns.AutoFit=1" the whole program will crash, but without xlApp.Columns.AutoFit=1, everything just fine.
23
2511
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) return s def descrambleLine(line):
9
3832
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 when I try to use the numbers for example Cell (1,1) has the number 50 in it Now I can read it and print it but when I say for example try to add or subtract from the number it gives errors. Here is my python code.
1
3641
by: chriswilliams | last post by:
This code prints output in rows like this: ****** ****** ****** How to make print in blocks like this? ***** ***** ****** ***** ***** ****** ***** ***** ***** start= int (raw_input("StartTable?"))
2
14653
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 me with the code to do this in Python? I recorded the macro >> Sub Macro2() ' ' Macro2 Macro '
15
64512
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
8365
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8788
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8563
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8646
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7390
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4200
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2776
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.