所以當我只顯示串列時,它顯示為:
A 22
WO 8
Name: 7, dtype: int64
當我嘗試 list[0] 時,它只列印值 22。
我如何列印整行,如:
A 22
我也想把它寫成一個excel表。我想為 A 和 WO 制作一個單獨的列,并在行中使用它們的相應值。請讓我知道如何實作
uj5u.com熱心網友回復:
這是使用 Pandas 將串列撰寫為 excel 并列印資料框中的第一行(或所有行)的分步指南。
import pandas as pd
list_1 = [0, 1, 2]
list_2 = ['A', 'B', 'C']
data_as_dictionary = {'Name':list_2, 'Value':list_1}
df = pd.DataFrame(data_as_dictionary)
# write df into excell
df.to_excel('df_as_excel.xlsx', index=None)
# print first row from the df
print(df.loc[[0]])
# if you already have an excel and want to print the rows:
# 1. load in excel
df2 = pd.read_excel('df_as_excel.xlsx', index_col=None)
# 2. print first row
print(df2.loc[[0]])
# 3. or if you want to print all rows in the df2
for row_number in range(len(df2)):
print(df2.loc[[row_number]])
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/317486.html
