python-3.x - 将数据从 url 加载到数据框

标签 python-3.x pandas url

我正在编写 pandas 教程,并希望将以下数据加载到数据框(我使用 python 3.6 和 pandas 0.23.0):

Data from URL

我知道如何从标准数据格式(csv、excel 等)加载数据,但现在知道如何处理手头的数据。 (可能有一个简单的解决方案(也许已经在SO上了?),但到目前为止我没有发现任何解决方案,因为我什至不知道我到底在看什么)。

最佳答案

只需使用 read_csv ,它与数据的 url 链接一起使用非常好:

url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/u.user'
df = pd.read_csv(url, sep='|')
print (df.head())
   user_id  age gender  occupation zip_code
0        1   24      M  technician    85711
1        2   53      F       other    94043
2        3   23      M      writer    32067
3        4   24      M  technician    43537
4        5   33      F       other    15213

关于python-3.x - 将数据从 url 加载到数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52495528/

相关文章:

python - 测试所有字典项是否为 'True' 的快速方法

python-3.x - 根据条件更改 pandas 数据框子组上特定列的值

javascript - jquery,正则表达式,制作动态 url

php - URL 参数值 - 不带参数名称 - 例如 google 收缩 URL

python - 将 CSV 导入 BigQuery 中的表时无法添加字段

python-3.x - 使用 Selenium 从容器的文本区域获取文本

python - 将 pandas DataFrame 索引转换为时间戳格式

python pandas crosstab 和积方阵

Python Dask - dataframe.map_partitions() 返回值

Angular 7 - 使用 queryParams 定义路由