Multi-line fields and inserting columns

We need to import our passwords from a format that is not explicity understood by Bitwarden.

The old tool exports to CSV, and I’ve build a simple Python script to change some column names as well as inserting a couple of new columns. The script I’m using is below:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import os, re, glob
import pandas as pd
df=pd.read_csv(glob.glob('accounts_*.csv')[0])
df['collections']=re.sub('folder-', '', os.path.basename(os.getcwd()))
df['type']='login'
result = df.rename(columns={'nickname': 'name', 'additionalInfo': 'notes', 'url': 'login_uri', 'username': 'login_username', 'password': 'login_password', 'twofaSecret': 'login_totp'})
result.to_csv("test.csv")
</code>
<code>import os, re, glob import pandas as pd df=pd.read_csv(glob.glob('accounts_*.csv')[0]) df['collections']=re.sub('folder-', '', os.path.basename(os.getcwd())) df['type']='login' result = df.rename(columns={'nickname': 'name', 'additionalInfo': 'notes', 'url': 'login_uri', 'username': 'login_username', 'password': 'login_password', 'twofaSecret': 'login_totp'}) result.to_csv("test.csv") </code>
import os, re, glob
import pandas as pd
df=pd.read_csv(glob.glob('accounts_*.csv')[0])
df['collections']=re.sub('folder-', '', os.path.basename(os.getcwd()))
df['type']='login'
result = df.rename(columns={'nickname': 'name', 'additionalInfo': 'notes', 'url': 'login_uri', 'username': 'login_username', 'password': 'login_password', 'twofaSecret': 'login_totp'})
result.to_csv("test.csv")

It’s working well except for one issue, each record has a notes field that can span multiple lines, e.g.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>nickname,username,password,additionalInfo
Some site,username,PASSWORD,Some website we use
Another site,username2,PASSWORD2,A longer description with a carriage return
And some more text
And more
And more
</code>
<code>nickname,username,password,additionalInfo Some site,username,PASSWORD,Some website we use Another site,username2,PASSWORD2,A longer description with a carriage return And some more text And more And more </code>
nickname,username,password,additionalInfo
Some site,username,PASSWORD,Some website we use
Another site,username2,PASSWORD2,A longer description with a carriage return
And some more text
And more
And more

All the records need the same two extra columns, so I’m adding them this way:

df[‘collections’]=’Some Collection’
df[‘type’]=’login’

The problem is it adds those columns on the multi-line fields, e.g.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>collections,type,name,login_username,login_password,notes
Some Collection,login,username,PASSWORD,Some website we use
Some Collection,login,Another site,A longer description with a carriage return
Some Collection,login,And some more text
Some Collection,login,And more
Some Collection,login,And more
</code>
<code>collections,type,name,login_username,login_password,notes Some Collection,login,username,PASSWORD,Some website we use Some Collection,login,Another site,A longer description with a carriage return Some Collection,login,And some more text Some Collection,login,And more Some Collection,login,And more </code>
collections,type,name,login_username,login_password,notes
Some Collection,login,username,PASSWORD,Some website we use
Some Collection,login,Another site,A longer description with a carriage return
Some Collection,login,And some more text
Some Collection,login,And more
Some Collection,login,And more

Actually Bitwarden is able to import the file successfully, just every line in the note is prefixed with Some Collection,login,.

I could use regex to remove the unwanted text, but I wondered if I could use pandas in a different way so it didn’t recognise every newline as a new record?

Thanks for any tips!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật