无法从pandas中获取字符串,而是获取到了数据类型。

huangapple go评论61阅读模式
英文:

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-
无法从pandas中获取字符串,而是获取到了数据类型。

> 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()) 

huangapple
  • 本文由 发表于 2023年6月27日 21:08:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76565220.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定