Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
webscrapping lists to dataframe
#3
Isn't there needless conversions in creating record_list?

>>> a = [1, 2, 3]                                                              
>>> b = 'abc'                                                                  
>>> c = [10, 20, 30] 
>>> for row in zip(a, b, c): 
....    print(row) 
....                                                                           
(1, 'a', 10)
(2, 'b', 20)
(3, 'c', 30)
>>> for row in list(zip(a, b, c)): 
....    print(row) 
....                                                                           
(1, 'a', 10)
(2, 'b', 20)
(3, 'c', 30)
>>> [list(item) for item in list(zip(a, b, c))]                                
[[1, 'a', 10], [2, 'b', 20], [3, 'c', 30]]
>>> list(zip(a, b, c))                                                         
[(1, 'a', 10), (2, 'b', 20), (3, 'c', 30)]
DataFrame data source can be iterable (documentation: data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame) therefore even converting to list is not necessary:

>>> df = pd.DataFrame(zip(a, b, c), columns = ('First', 'Second', 'Third'))
>>> df
   First Second  Third
0      1      a     10
1      2      b     20
2      3      c     30
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
webscrapping lists to dataframe - by kirito85 - Jun-10-2019, 02:31 AM
RE: webscrapping lists to dataframe - by snippsat - Jun-10-2019, 05:39 AM
RE: webscrapping lists to dataframe - by perfringo - Jun-10-2019, 06:46 AM
RE: webscrapping lists to dataframe - by kirito85 - Jun-10-2019, 06:55 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Webscrapping sport betting websites KoinKoin 3 5,439 Nov-08-2023, 03:00 PM
Last Post: LoriBrown
  webscrapping links from pandas dataframe Wolverin 2 2,278 Aug-28-2023, 12:07 PM
Last Post: Gaurav_Kumar
  Webscrapping of Images that requires Authentication junos4350 1 1,983 Jun-08-2020, 08:32 AM
Last Post: alekson
  webscrapping links and then enter those links to scrape data kirito85 2 3,202 Jun-13-2019, 02:23 AM
Last Post: kirito85

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020