0
存儲結果我用熊貓來處理一些csv文件,但我有存放在變量的結果,並打印出來,因爲它是麻煩。Python的大熊貓麻煩變量
這是我的代碼。
df = pd.read_csv(MY_FILE.csv, index_col=False, header=0)
df2 = df[(df['Name'])]
# Trying to get the result of Name to the variable
n = df2['Name']
print(n)
而結果是我得到:
1 jake
Name: Name, dtype: object
我的問題:
是否有可能只是「傑克」存儲在一個變量「n」,這樣我可以把它無論何時我需要它?
EG:打印(N)
結果:Jake
這是我構建的代碼
def name_search():
list_to_open = input("Which list to open: ") + ".csv"
directory = "C:\Users\Jake Wong\PycharmProjects\box" "\\" + list_to_open
if os.path.isfile(directory):
# Search for NAME
Name_id = input("Name to search for: ")
df = pd.read_csv(directory, index_col=False, header=0)
df2 = df[(df['Name'] == Name_id)]
# Defining the name to save the file as
n = df2['Name'].ix[1]
print(n)
這是什麼是CSV文件
S/N,Name,Points,test1,test2,test3
s49,sing chun,5000,sc,90 sunrsie,4984365132
s49,Alice Suh,5000,jake,88 sunrsie,15641816
s1231,Alice Suhfds,5000,sw,54290 sunrsie,1561986153
s49,Jake Wong,5000,jake,88 sunrsie,15641816
OMG!你是個天才!!非常感謝:D –
嗯,我還有另一個qns。看起來如果這個名字有兩個單詞「Jake Wong」,它會引發錯誤? KeyError:2.任何想法? –
任何人有任何想法如何這可以解決,如果它的2個或更多的單詞? –