简体   繁体   English

Python pandas dataframe 如何将 Z78E6221F6393D1356681DB398FtrCE4 作为第 6 行和第 6 行

[英]Python pandas dataframe how to output th as a column and tr as the row

Quite new to python and trying to learn from different forums and such.对 python 很陌生,并试图从不同的论坛等学习。 I am scraping using selenium and this time i wanted to get a table.我正在使用 selenium 进行抓取,这次我想要一张桌子。 The scraping and the output works fine.But i would like to get titles as columns and the tr value as the row.. today my output looks like this刮擦和 output 工作正常。但我想将标题作为列,将 tr 值作为行。今天我的 output 看起来像这样

在此处输入图像描述

but i want the output like this..但我想要这样的 output ..

在此处输入图像描述

This is the code这是代码

# Import Library
from selenium import webdriver
import pandas as pd
# Open Browser
driver = webdriver.Chrome(path')
# Get the  URL
url = 'give url'
driver.get(url)
driver.maximize_window()
# Read and Convert Web table into data frame
webtable_df = pd.read_html(driver.find_element_by_xpath('').get_attribute('outerHTML'))[0]
# Write() to excel file
webtable_df.to_excel (r'path', index = False, header=True)

Transpose the data matrix (row to column here) 置数据矩阵(此处为行到列)

>>> import pandas as pd
>>> df = pd.DataFrame({'a':[1,2,3], 'b':[4,5,6]})
>>> df
   a  b
0  1  4
1  2  5
2  3  6
>>> df.T # there is df.transpose() too.
   0  1  2
a  1  2  3
b  4  5  6

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM