[英]Python Pandas printing out values of each cells
I am trying to fetch values from an excel file using pandas dataframe and print out the values of each cells. 我试图使用pandas数据帧从excel文件中获取值并打印出每个单元格的值。 Im using
read_excel()
to populate the dataframe, and I am looking for specific rows using the following line of code: 我使用
read_excel()
来填充数据帧,我正在使用以下代码行查找特定的行:
df.loc[df['Parcel_ID'] == parcel]
parcel being an arbitrary input from the user. parcel是来自用户的任意输入。 And I simply use this to print out the cells:
我只是用它来打印细胞:
row = df.loc[df['Parcel_ID'] == parcel]
print row['Category']
print row['Sub_Category']
.
.
(more values)
What I want is only the values from the cells, yet I get dtypes, names of the column, and other junks that I don't want to see. 我想要的只是来自单元格的值,但我得到了dtypes,列的名称以及我不想看到的其他容器。 How would I only print out the value from each cells?
我怎么只打印每个单元格的值?
If you have several values in your row you could use following: 如果您的行中有多个值,则可以使用以下内容:
row['Category'].values.tolist()
row['Sub_Category'].values.tolist()
IIUC the following should work: IIUC以下应该有效:
print row['Category'][0]
print row['Sub_Category'][0]
what is returned will be a Series in your case a Series with a single element which you index into to return a scalar value 在您的情况下,返回的将是一个系列,其中包含一个元素,您可以将其编入索引以返回标量值
How to find a value in a column (Column 1 name) by another value in another column (Column 2 name) 如何在列(列1名称)中查找另一列中的另一个值(列2名称)
df = pd.read_excel('file.xlsm','SheetName') #Get a excel file sheet
Then you have two ways to get that: 然后你有两种方法可以做到这一点:
First Way ---> 第一种方式--->
Value_Target = df.loc[df['Column1name']== 'Value_Key']['Column2name'].values
Second Way ---> 第二种方式--->
Value_Target = df['Column1name'][df['Column2name']=='Value_Key'].values[0]
Value_Key is the value in a column you have Value_Target is the value you want to find using Value_Key Value_Key是您拥有的列中的值Value_Target是您要使用Value_Key查找的值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.