[英]Reading Quip Spreadsheet with quip-api and pandas
我已經開始探索 Quip API。
我在 Quip 中創建了一個電子表格,其中包含以下詳細信息:
ID | 名稱 |
---|---|
1 | 哈利 |
2 | 赫敏 |
3 | 朗 |
這是我嘗試從 Quip 中讀取的方式:
import quip
import pandas as pd
import numpy as np
import html5lib
client = quip.QuipClient(token, base_url = baseurl)
rawdictionary = client.get_thread(thread_id)
dfs=pd.read_html(rawdictionary['html'])
raw_df = dfs[0]
raw_df.drop(raw_df.columns[[0]], axis = 1, inplace = True)
#raw_df.dropna(axis=0,inplace=True)
print(raw_df.replace(r'^\s+$', np.nan, regex=True))
我嘗試用 nan 對象刪除行,並嘗試用 nan 替換空白字符串。 但是,我仍然看到這些空行和列出現在數據框中,例如:
A B C D E F G H I J K L M N O P
0 id name
1 1 harry
2 2 hermione
3 3 ron
4
5
6
7
8
9
10
11
12
13
14
15
16
17
問題
id
和name
的行?print(raw_df)
時添加raw_df.dropna(axis=0,inplace=True)
print(raw_df)
,我得到None
。 為什么?Quip 會自動使用 \ Unicode 字符引入許多額外的空白列和行。
這就是我解決這個問題的方法:
import quip
import pandas as pd
import numpy as np
import html5lib
client = quip.QuipClient(token, base_url = baseurl)
rawdictionary = client.get_thread(thread_id)
dfs=pd.read_html(rawdictionary['html'])
raw_df = dfs[0]
raw_df.columns=raw_df.iloc[0] #Make first row as column header
raw_df=raw_df[1:] #After the above step, the 1st two rows become duplicate. Delete the 1st row.
raw_df=raw_df[attribs]
cleaned_df = raw_df.replace(np.nan, 'N/A')
cleaned_df = cleaned_df.replace('\u200b', np.nan)
cleaned_df.dropna(axis=0,how='any',inplace=True)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.