英文:
Not able to get string out of pandas rather getting a datatype
问题
Here is the translated code part without the translation of your request:
read_file = pd.read_csv('settings.txt', header=None)
read_file.columns = ['username', 'password']
read_file.to_csv('settings.csv', index=None)
sett = pd.read_csv('settings.csv')
mailid = sett['username']
passw = sett['password']
print(mailid)
If you have any other code-related questions or need assistance with this code, please feel free to ask.
英文:
read_file = pd.read_csv (r'settings.txt', header = None)
read_file.columns = ['username', 'password']
read_file.to_csv (r'settings.csv',index=None)
sett = pd.read_csv('settings.csv')
mailid= sett['username']
passw= sett['password']
print(mailid)
> I wanted to get only the string (i.e. asv@gmail.com) but this is what I am getting-
> How do I change this to a string?
答案1
得分: 1
如果您只想将mailid列的值作为字符串打印出来,您可以使用.values属性来访问底层的NumPy数组并将其转换为常规的Python列表。
import pandas as pd
read_file = pd.read_csv('settings.txt', header=None)
read_file.columns = ['username', 'password']
read_file.to_csv('settings.csv', index=None)
sett = pd.read_csv('settings.csv')
mailid = sett['username']
passw = sett['password']
print(mailid.values.tolist())
英文:
If you want to print just the values of the mailid column as strings, you can use the .values attribute to access the underlying NumPy array and convert it to a regular Python list.
import pandas as pd
read_file = pd.read_csv('settings.txt', header=None)
read_file.columns = ['username', 'password']
read_file.to_csv('settings.csv', index=None)
sett = pd.read_csv('settings.csv')
mailid = sett['username']
passw = sett['password']
print(mailid.values.tolist())
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论