重命名DataFrame中groupby和count的输出列

2024-09-30 12:25:27 发布

您现在位置:Python中文网/ 问答频道 /正文

你能告诉我如何计算以下数据的每项专利的引用次数吗

"CITING","CITED"
3858241,956203
3858241,1324234
3858241,3398406
3858241,3557384
3858241,3634889
3858242,1515701
3858242,3319261
3858242,3668705
3858242,3707004
3858243,2949611
3858243,3146465
3858243,3156927

“引用”栏包含专利号

所需输出为以下格式的数据帧:

 +--------+------+
 |NPatent|ncitations|
 +--------+------+
 | 3060453|  3   |
 | 3390168|  6   |
 | 3626542| 18   |
 | 3611507|  5   |
 | 3000113|  4   |

我目前正在使用以下代码,该代码没有生成所需的输出:

# Importing Pandas 
import pandas as pd

# Reading the file in zipped format and save it to a DataFrame
df = pd.read_csv('/datos/cite75_99.txt.bz2', compression='bz2', header=0, sep=',', quotechar='"')

df = df.groupby('CITED').CITING.nunique()

print(df)

如果您能帮助我获得所需的数据帧,我将不胜感激

谢谢大家!


Tags: 数据代码pandasdf格式次数专利pd

热门问题