第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

有沒(méi)有辦法將此數(shù)據(jù)格式轉(zhuǎn)換為 CSV?

有沒(méi)有辦法將此數(shù)據(jù)格式轉(zhuǎn)換為 CSV?

ibeautiful 2022-05-24 10:43:28
我有大量帶有格式的提取 Json 文件。我想知道是否有任何方法可以將其轉(zhuǎn)換為以列作為特征和行中的值的 CSV。{"state": "New Jersey", "text": "RT @joncoopertweets: Register to join the #WeThePeopleMarch on September 21st in Washington, D.C. \u2014 or one of the 50+ marches that will be\u2026", "has_emoji": false, "created_at": "Mon Sep 02 16:32:05 +0000 2019", "id": 1168562246349467649, "entities": {"hashtags": [{"text": "WeThePeopleMarch", "indices": [42, 59]}], "urls": [], "user_mentions": [{"screen_name": "joncoopertweets", "name": "Jon Cooper", "id": 27493883, "id_str": "27493883", "indices": [3, 19]}], "symbols": []}, "source": "Twitter for iPad", "location": "Leonia, NJ", "verified": false, "geocode": null}{"state": "Indiana", "text": "RT @dariusherron1: Don\u2019t nobody love they girl like Mexicans ", "has_emoji": false, "created_at": "Mon Sep 02 16:32:05 +0000 2019", "id": 1168562246378827776, "entities": {"hashtags": [], "urls": [{"url": "", "expanded_url": "", "display_url": "", "indices": [61, 84]}], "user_mentions": [{"screen_name": "dariusherron1", "name": "Darius Herron", "id": 1680891876, "id_str": "1680891876", "indices": [3, 17]}], "symbols": []}, "source": "Twitter for iPhone", "location": "Indianapolis, IN", "verified": false, "geocode": null}
查看完整描述

2 回答

?
躍然一笑

TA貢獻(xiàn)1826條經(jīng)驗(yàn) 獲得超6個(gè)贊

我對(duì)您的預(yù)期輸出并不完全清楚(請(qǐng)參閱@user5783745 答案的評(píng)論和討論)。您的 JSON 字符串包含一些嵌套對(duì)象,list如果您使用jsonlite::fromJSON. 由于您沒(méi)有為您提供的示例數(shù)據(jù)提供匹配的預(yù)期輸出,因此可能有不同的方法來(lái)處理這些嵌套條目。


一種可能性是解析 JSON 字符串,然后在綁定行之前解析兩次flatten結(jié)果。list


library(tidyverse)

library(jsonlite)

map(json, ~fromJSON(.x) %>% flatten() %>% flatten()) %>% bind_rows()

## A tibble: 2 x 15

#  state text  has_emoji created_at     id indices screen_name name  id_str

#  <chr> <chr> <lgl>     <chr>       <dbl> <list>  <chr>       <chr> <chr>

#1 New … WeTh… FALSE     Mon Sep 0… 2.75e7 <int [… joncoopert… Jon … 27493…

#2 Indi… "RT … FALSE     Mon Sep 0… 1.68e9 <int [… dariusherr… Dari… 16808…

## … with 6 more variables: source <chr>, location <chr>, verified <lgl>,

##   url <chr>, expanded_url <chr>, display_url <chr>

結(jié)果對(duì)象是一個(gè)tibble帶有一些list列的對(duì)象。要存儲(chǔ)為 CSV,您可以排除這些list列。


樣本數(shù)據(jù)

json <- c(

    '{"state": "New Jersey", "text": "RT @joncoopertweets: Register to join the #WeThePeopleMarch on September 21st in Washington, D.C. \u2014 or one of the 50+ marches that will be\u2026", "has_emoji": false, "created_at": "Mon Sep 02 16:32:05 +0000 2019", "id": 1168562246349467649, "entities": {"hashtags": [{"text": "WeThePeopleMarch", "indices": [42, 59]}], "urls": [], "user_mentions": [{"screen_name": "joncoopertweets", "name": "Jon Cooper", "id": 27493883, "id_str": "27493883", "indices": [3, 19]}], "symbols": []}, "source": "Twitter for iPad", "location": "Leonia, NJ", "verified": false, "geocode": null}',

    '{"state": "Indiana", "text": "RT @dariusherron1: Don\u2019t nobody love they girl like Mexicans ", "has_emoji": false, "created_at": "Mon Sep 02 16:32:05 +0000 2019", "id": 1168562246378827776, "entities": {"hashtags": [], "urls": [{"url": "", "expanded_url": "", "display_url": "", "indices": [61, 84]}], "user_mentions": [{"screen_name": "dariusherron1", "name": "Darius Herron", "id": 1680891876, "id_str": "1680891876", "indices": [3, 17]}], "symbols": []}, "source": "Twitter for iPhone", "location": "Indianapolis, IN", "verified": false, "geocode": null}')



查看完整回答
反對(duì) 回復(fù) 2022-05-24
?
一只斗牛犬

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超2個(gè)贊

您可以輕松地將其轉(zhuǎn)換為更易于使用 (a list) 的數(shù)據(jù)格式,但此后如何使用它取決于您自己。在這種情況下,數(shù)據(jù)列表不會(huì)自動(dòng)變成 a data.frame- 您必須考慮如何轉(zhuǎn)換它(假設(shè)某些列表項(xiàng)是單個(gè)項(xiàng),而其他列表項(xiàng)本身就是data.frames


a <- '{"state": "New Jersey", "text": "RT @joncoopertweets: Register to join the #WeThePeopleMarch on September 21st in Washington, D.C. \u2014 or one of the 50+ marches that will be\u2026", "has_emoji": false, "created_at": "Mon Sep 02 16:32:05 +0000 2019", "id": 1168562246349467649, "entities": {"hashtags": [{"text": "WeThePeopleMarch", "indices": [42, 59]}], "urls": [], "user_mentions": [{"screen_name": "joncoopertweets", "name": "Jon Cooper", "id": 27493883, "id_str": "27493883", "indices": [3, 19]}], "symbols": []}, "source": "Twitter for iPad", "location": "Leonia, NJ", "verified": false, "geocode": null}' 


library(jsonlite)

library(dplyr)

a <- a %>% fromJSON 


new_dataframe <- data.frame(state=character(), 

                                text=character(), 

                                has_emoji=character(), 

                                id=character(), 

                                entities=character(), stringsAsFactors = FALSE)



new_dataframe[1, ] <- c(a$state, a$text, a$has_emoji, a$created_at, a$id) 


查看完整回答
反對(duì) 回復(fù) 2022-05-24
  • 2 回答
  • 0 關(guān)注
  • 104 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)