简体   繁体   English

将非结构化 TXT 转换为 CSV

[英]Converting unstructured TXT to CSV

I am trying to use python to put all of this market research data into a csv file, currently it is in an unstructured txt file.我正在尝试使用 python 将所有这些市场研究数据放入csv文件中,目前它位于非结构化txt文件中。

I want to get it in a format so that the name of each company is the row title, and the column titles are as follows:我想得到一个格式,这样每家公司的名字就是行标题,列标题如下:

  • Description描述
  • Founded year成立年份
  • Headquarters总部
  • Website网站
  • Founders创始人

I am confused on where I should go from this point.从这一点开始,我对 go 应该在哪里感到困惑。

    NestAway is one of the top proptech startups for 2020
    
    NestAway This Bangalore-based startup is a home rental network that aims to provide better rental solutions via design and technology. Their motto is to assist customers in booking, finding, and moving into a rental home of choice across Indian cities. All of this is made possible within an application. They also help their customer’s move-in, ask for services from tap leakage to door lock broken, rental payment, etc. Alongside this, they also assist customers in moving out. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2015
    
    Headquarters: Bangalore, India
    
    Website: www.nestaway.com
    
    LinkedIn: www.linkedin.com/company/9334060/
    
    Founders: Amarendra Sahu, Deepak Dhar, Jitendra Jagadev, Smruti Parida
    
     
    
    Ucommune is one of the top proptech startups for 2020
    
    This startup offers co-working space solutions. They also have provision for long-term leasing, hot desk, and corporate customization and professional solutions. They provide services to small-to-medium enterprises across China, Singapore, New York City, San Francisco in California, and London in the United Kingdom. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2015
    
    Headquarters: Beijing, China
    
    Website: www.ucommune.com
    
    LinkedIn: www.linkedin.com/company/ucommune
    
    Founders: Mao Daqing
    
     
    
    Square Yards is one of the top proptech startups for 2020
    
    One of the major players in the Indian proptech market, Square Yards, is regarded as the largest player and mortgage marketplace in India. It has a global presence covering ten countries and 30 cities. They operate the largest distribution capacity for Primary real estate in India/NRI markets. Along with this, Square Yards also operates various proprietary tech tools and platforms for all stakeholders. This includes developers, banks, consumers and sales agents. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2013
    
    Headquarters: Gurgaon, India
    
    Website: www.squareyards.com
    
    LinkedIn: www.linkedin.com/company/square-yards
    
    Founders: Kanika Gupta, Tanuj Shori
    
     
    
    Stanza Living is one of the top proptech startups for 2020
    
    This co-living platform is ideal for students scouting for a new place. The premium, high quality, student accommodation concept aims to disrupt the multi-billion-dollar student housing market. They are putting students and their needs at the core of the product and service design, development, and execution. The startup offers smart space planning in rooms from options to gamify food, celebrate special moments, etc. In short, they are challenging the status quo of student accommodation. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2017
    
    Headquarters: New Delhi, India
    
    Website: www.stanzaliving.com
    
    LinkedIn: www.linkedin.com/company/stanzaliving
    
    Founders: Anindya Dutta, Sandeep Dalmia
    
     
    
    Livspace is one of the top proptech startups for 2020
    
    Livspace is an e-commerce-based interior design company that designs, delivers, and installs interiors. They hire the best professional designers to ensure that the customer designs are functional and aesthetically appealing homes. The services offered include space planning, picking the right furniture, color combinations and designing ergonomic layouts to match your preferences and lifestyle. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2012
    
    Headquarters: Bangalore, India
    
    Website: www.stanzaliving.com
    
    LinkedIn: www.linkedin.com/company/livspace
    
    Founders: Anuj Srivastava, Ramakant Sharma, Shagufta Anurag
    
     
    
    Zolo is one of the top proptech startups for 2020
    
    This startup has emerged as India’s largest company offering fully managed co-living spaces. It was founded by alumni of IIM, IIT, and ISB, Zolo, to solve the problem of living for students and young professionals. The startup evaluates the traditional PG/service apartments/hostels and offering all kinds of basic and luxury living amenities. They maintain standard quality across properties with the help of technology. Zolo offers fully furnished rooms, hygienic and healthy food, daily housekeeping, Internet facilities, security, etc. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2015
    
    Headquarters: Bangalore, India
    
    Website: www.zolostays.com
    
    LinkedIn: www.in.linkedin.com/company/zolostays
    
    Twitter: www.twitter.com/zolostays
    
    Founders: Akhil Sikri, Isha Choudhry, Nikhil Sikri, Sneha Choudhry
    
     
    
    Hmlet is one of the top proptech startups for 2020
    
    This startup is a co-living company providing rooms and full apartments for young working professionals. Hmlet caters to an international workforce and aims to help them balance their lifestyles, finances, and natural desire to connect. It enables individuals to come together as a community to actively collaborate and contribute to a more purposeful life. Along with Singapore, it has offices in Tokyo, Hong Kong, Sydney, and soon in Melbourne. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2016
    
    Headquarters: Singapore
    
    Website: www.hmlet.com
    
    LinkedIn: www.linkedin.com/company/13224292
    
    Twitter: www.twitter.com/hmlet_official
    
    Founders: Yoan Kamalski, Zenos Schmickrath
    
     
    
    99.Co is one of the top proptech startups for 2020
    
    99.co is a map-based property search engine. With this engine, consumers have the option to use smart algorithms. They further offer housing renters, buyers, and property agents with quick and speedy property search experience in Singapore, which is efficient and transparent. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year:  2014
    
    Headquarters: Singapore
    
    Website:  www.99.co 
    
    LinkedIn: www.linkedin.com/company/99-co
    
    Twitter: www.twitter.com/99dotco
    
    Founders: Conor McLaughlin, Darius Cheung, Dominic Ee, Ruiwen Chua, Saurabh Mandar, Yan Phun
    
     
    
    Property Finder is one of the top proptech startups for 2020
    
    PropertyFinder operates online real estate portals for properties across Dubai and provides visitors with search facilities. This covers a multitude of sections like residential and commercial properties for rent or for sale, real estate news, home advice, and buying and selling guides. They provide users with the tools to help consumers find the properties as per their needs. They also work with brokers to list properties in one convenient site — making it easier to see all of the information about those properties. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2005
    
    Headquarters: Dubai, UAE
    
    Website: www.propertyfinder.ae/
    
    LinkedIn: www.linkedin.com/company/propertyfinder-ae
    
    Twitter: www.twitter.com/property_finder   
    
    Founders: Michael Lahyani, Renan Bourdeau
    
     
    
    Guesty is one of the top proptech startups for 2020
    
    Guesty is a platform that offers property managers and management companies with an end-to-end solution for easing the complex operational needs of short-term rentals. With this platform, the consumers can seamlessly manage listings from multiple online travel agencies at a global level. They can further utilize the company’s advanced tools, which include Channel Manager, Unified Inbox, Multi-Calendar, etc. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2013
    
    Headquarters: Tel Aviv, Israel
    
    Website: www.guesty.com
    
    LinkedIn: www.linkedin.com/company/guesty
    
    Twitter: www.twitter.com/guesty
    
    Founders: Amiad Soto, Koby Soto
    
     
    
    PropertyGuru is one of the top proptech startups for 2020
    
    PropertyGuru is one of Asia’s leading online property company which offers operates rental and sale listing sites — mainly for Southeast Asia. It provides the property seekers with a wide range of about 2 million homes along with in-depth insights, and solutions. Their services span across Singapore, Malaysia, Thailand, Indonesia, and Vietnam. It has now emerged as a high-growth technology company with a robust portfolio and offers the best-in-class developer sales enablement platform, ePropertyTrack, etc. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2006
    
    Headquarters: Singapore
    
    Website: www.propertygurugroup.com
    
    LinkedIn: www.linkedin.com/company/623046
    
    Twitter: www.twitter.com/SGPropertyGuru
    
    Founders: Amiad Soto, Koby Soto
    
     
    
    Ziroom is one of the top proptech startups for 2020
    
    Ziroom is a rental services company that offers home rental and property management services. It is rather different from the conventional intermediary leasing model, as it is an O2O COMPANY. They offer professional housing asset management services. The number of freely managed houses has exceeded 600,000, and their owners have exceeded 300,000. In total, the number of freestanding customers has exceeded 1.4 million. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2011
    
    Headquarters: Beijing
    
    Website: www.ziroom.com
    
    LinkedIn: www.linkedin.com/company/ziroom/
    
    Founders: Lin Xiong
    
     
    
    Furlenco is one of the top proptech startups for 2020
    
    Furlenco is India’s pioneering Home Furniture Subscription Program and was created for helping users find well-designed, sophisticated, and affordable furniture on rent. They offer a range of curated home furniture experiences, which have been customized and designed to suit the lifestyle, needs of varied audiences spanning students to families and expatriates. They provide convenient, cost-effective and offer access to quality furniture with the added advantage of exchanging it at will depending on your requirements. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2011
    
    Headquarters: Bangalore, India
    
    Website: www.furlenco.com
    
    LinkedIn: www.linkedin.com/company/furlenco
    
    Twitter: www.twitter.com/furlenco
    
    Founders: Ajith Karimpana
    
     
    
    Kujiale is one of the top proptech startups for 2020
    
    This online information and design platform provides customers with information and reviews on businesses related to home decoration and furnishing. The startup had been launched by Hang Chen and is operated from Hangzhou, China.  Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2011
    
    Headquarters: Hangzhou, Zhejiang, China
    
    Website: www.kujiale.com
    
    LinkedIn: www.linkedin.com/company/酷家乐/
    
    Founders: Hang Chen
    
     
    
    Design Cafe is one of the top proptech startups for 2020
    
     
    
    This award-winning Architecture & Interior Design startup focusses on the residential segment. It offers users with online venture brings you the best designs, showcases them online, and creates easy processes to customize them for free. Based on their passion for providing consumers with a well-designed home makes, they make space for everything that’s part of your life. On the whole, it ensures that good design helps to change the way you live, work and play. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2015
    
    Headquarters: Bangalore, India
    
    Website: www.designcafe.com
    
    LinkedIn: www.in.linkedin.com/company/design-cafe
    
    Twitter: www.twitter.com/dc_designcafe
    
    Founders: Gita Ramanan, Shezan Bhojani
    
     
    
    Housejoy is one of the top proptech startups for 2020
    
    Housejoy offers a one-stop solution to different home needs ranging from construction to maintenance, professionally and conveniently. The web platform helps homeowners browse and book quality service providers like electricians, plumbers etc. They create incomparable customer experience by providing homeowners with a seamless way to instantly book/schedule various services from trusted professionals. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2014
    
    Headquarters: Bangalore, India
    
    Website: www.housejoy.in
    
    LinkedIn: www.linkedin.com/company/housejoy
    
    Twitter: www.twitter.com/housejoyindia
    
    Founders: Arjun Kumar, Sunil Goel
    
     
    
    CoHive is one of the top proptech startups for 2020
    
    This startup is Indonesia’s largest coworking space company and was earlier known as EV Hive. They provide a cohesive working and living experience via options of coworking, coliving, co-retail, and shared event spaces. They connect and enable startups as well as micro, small and medium enterprises – SMEs to grow their businesses. They have approximately 9.000 members working from 33 locations in four cities that include Jakarta, Medan, Yogyakarta, and Bali. About 80% of their members are startups and SMEs. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2015
    
    Headquarters: Jakarta, Indonesia
    
    Website: www.cohive.space
    
    LinkedIn: www.linkedin.com/company/cohive
    
    Twitter: www.twitter.com/cohivespace
    
    Founders: Carlson Lau, Ethan Choi, Jason Lee
    
     
    
    Zhuge.com is one of the top proptech startups for 2020
    
    Zhuge is a leading big data and AI startup within the real estate segment in China. They offer users real estate information and search services for properties in their cities. Their unique search engine can clean and reorganize the entire website data every 10 minutes to ensure the comprehensiveness and effectiveness of the listing. They gain insight into the changes in different listings data from the micro-level and foresee trend of understanding the entire real estate market. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2015
    
    Headquarters: Beijing, China
    
    Website: www.bj.zhuge.com
    
      
    
    Ke.com is one of the top proptech startups for 2020
    
    Founded in 2018, Beike is an open platform. It enables agents to use resources more efficiently for creating a high-quality ecosystem that comprises of second-hand property, new property, rental property and decoration. It has been specifically designed to meet the requirement of the ever-increasing Chinese families seeking overseas property. With more than 10,000 listing online, Beike covers U.S., Canada, Australia, New Zealand, the U.K., France Germany, Singapore, Japan, Thailand, and Korea. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2018
    
    Headquarters: Beijing, China
    
    Website: www.ke.com
    
    LinkedIn: www.linkedin.com/company/beike/about/
    
     
    
    Oxfordcaps is one of the top proptech startups for 2020
    
    Oxfordcaps is one of the first startups in Asia that is a tech-enabled student housing company. They provide student-housing products with the full-stack service model and have three accommodation options to offer students. These properties are furnished well and come with all modern amenities. Here is some more information about this venture, one of the top proptech startups for 2020.
    
    Founding Year: 2017
    
    Headquarters: Singapore
    
    Website: www.oxfordcaps.com
    
    LinkedIn: www.linkedin.com/company/13333368/
    
    Twitter: www.twitter.com/oxfordcaps
    
    Founders: Annu Talreja, Priyanka Gera
    
     
    
    Top startups in North America

I started by using print statements to diagnois this challenge:我首先使用打印语句来诊断这个挑战:

with open('example.txt','r') as file_handle:
    example_file_content = file_handle.read().split("\n")

new_company_line = -10
for index, line in enumerate(example_file_content):
    if index == new_company_line+2:
        print("description:", line)
    if "is one of the top" in line:
        print("company name =", line.split(" ")[0])
        new_company_line = index
    if line.startswith("Founding Year"):
        print('founding year =',line.split(":")[1].strip())
    if line.startswith("Headquarters"):
        print("headquarters = ",line.split(":")[1].strip())
    if line.startswith("Website"):
        print("website = ",line.split(":")[1].strip())
    if line.startswith("Founders"):
        print("founders =",line.split(":")[1].strip())            

Then I converted the print statements to a dictionary然后我将打印语句转换为字典

with open('example.txt','r') as file_handle:
    example_file_content = file_handle.read().split("\n")

new_company_line = -10
list_of_dicts = []
company_dict = {}
for index, line in enumerate(example_file_content):
    if index == new_company_line+2:
        company_dict["description:"]= line
    if "is one of the top" in line:
        if len(company_dict.keys())>1:
            list_of_dicts.append(company_dict)
        company_dict = {}
        company_dict["company name"] = line.split(" ")[0]
        new_company_line = index
    if line.startswith("Founding Year"):
        company_dict['founding year']=line.split(":")[1].strip()
    if line.startswith("Headquarters"):
        company_dict["headquarters"]=line.split(":")[1].strip()
    if line.startswith("Website"):
        company_dict["website"]=line.split(":")[1].strip()
    if line.startswith("Founders"):
        company_dict["founders"]=line.split(":")[1].strip()    

Finally, save the list of dicts to a dataframe and dump to CSV最后,将字典列表保存到 dataframe 并转储到 CSV

import pandas
df = pandas.DataFrame(list_of_dicts)
df.to_csv("output.csv")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM