如何将 GitHub 制作成 pandas DataFrame? [复制]
Posted
技术标签:
【中文标题】如何将 GitHub 制作成 pandas DataFrame? [复制]【英文标题】:How do I make a GitHub into a pandas DataFrame? [duplicate] 【发布时间】:2021-12-15 03:45:19 【问题描述】:如何将此CSV file 导入到我的 JupyterLab 数据帧中?
我希望将它转移到一个名为 Titanic 的新 DataFrame 中。我已经进行了 Google 搜索,并查看了:
Pandas.read_csv() function? 我知道 JupyterLab 有一个 read_csv
函数可以解决这个问题。
我试过了:
import "https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv" as Titanic
但这引发了一个错误:
File "<ipython-input-1-67adbf7f2871>", line 2
import "https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv" as Titanic
SyntaxError: invalid syntax
【问题讨论】:
您能否格式化您的问题,使其易于阅读并且清楚地解释您想要什么以及您已经尝试过什么?见:***.com/help/how-to-ask 你误解了你想要做什么。看看this 的回答,这就是你想要做的。 【参考方案1】:简单地说:
import pandas as pd
dataset = pd.read_csv("https://raw.githubusercontent.com/pandas-dev/pandas/master/doc/data/titanic.csv", sep=",")
给出:
PassengerId Survived Pclass \
0 1 0 3
1 2 1 1
2 3 1 3
3 4 1 1
4 5 0 3
.. ... ... ...
886 887 0 2
887 888 1 1
888 889 0 3
889 890 1 1
890 891 0 3
Name Sex Age SibSp \
0 Braund, Mr. Owen Harris male 22.0 1
1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1
2 Heikkinen, Miss. Laina female 26.0 0
3 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1
4 Allen, Mr. William Henry male 35.0 0
.. ... ... ... ...
886 Montvila, Rev. Juozas male 27.0 0
887 Graham, Miss. Margaret Edith female 19.0 0
888 Johnston, Miss. Catherine Helen "Carrie" female NaN 1
889 Behr, Mr. Karl Howell male 26.0 0
890 Dooley, Mr. Patrick male 32.0 0
Parch Ticket Fare Cabin Embarked
0 0 A/5 21171 7.2500 NaN S
1 0 PC 17599 71.2833 C85 C
2 0 STON/O2. 3101282 7.9250 NaN S
3 0 113803 53.1000 C123 S
4 0 373450 8.0500 NaN S
.. ... ... ... ... ...
886 0 211536 13.0000 NaN S
887 0 112053 30.0000 B42 S
888 2 W./C. 6607 23.4500 NaN S
889 0 111369 30.0000 C148 C
890 0 370376 7.7500 NaN Q
[891 rows x 12 columns]
【讨论】:
以上是关于如何将 GitHub 制作成 pandas DataFrame? [复制]的主要内容,如果未能解决你的问题,请参考以下文章