主頁 > 軟體設計 > 在重復行中使用for回圈結果追加到df

在重復行中使用for回圈結果追加到df

2022-01-25 18:45:59 軟體設計

我有一個串列物件json_reponse,其中包含 28 個推文物件,其中提到了兩個不同的政客,即each_dict(2x14)。我正在嘗試檢索author_id, created_at, tweet_id, text, bio, 上的資料image_url并非所有 28 個物件都有bioor image_url因此 #2 和 #3 中的 if-else 陳述句。我的代碼檢索author_idcreated_attweet_idtext符合市場預期。但是,bioimage_url資料在 14 行中復制每個政治家的最后一個物件,如print(df).

我嘗試了不同的縮進,但它并沒有解決問題。我回圈的方式是否存在基本錯誤json_response

一看結構json_response注意:由于字符限制,我洗掉了一些物件json_response

print(json.dumps(json_response, indent=4, sort_keys=True))  # look at json_response object.
[
    {
        "data": [
            {
                "author_id": "737885223858384896",
                "created_at": "2021-03-26T21:56:02.000Z",
                "id": "1375567243082338314",
                "text": "@hogan_1969 @LindseyGrahamSC LOL She Blocked me.. could not admit the truth could she now. okay so where is her source for the shirts? and that is what he said. I (quote) We immediately surge the border all those seeking asylum. What about his lie about the cages? no Answer lol."
            },
            {
                "author_id": "27327319",
                "created_at": "2021-03-02T11:53:16.000Z",
                "id": "1366718245521211393",
                "text": "@fedupinNHtoo @LindseyGrahamSC Exactly. I asked that question of a Republican on Facebook last night and she blocked me"
            },
            {
                "author_id": "917634626247647232",
                "created_at": "2021-02-28T18:16:45.000Z",
                "id": "1366089974907432961",
                "text": "@gop this is for you! @tedcruz @LindseyGrahamSC @MittRomney @mikepompeo\n#BitchyMcC blocked me!\ud83d\udc4d\nWatch \"Jack Off Jill - Hypocrite   lyrics\" on YouTube [link here]"
            },
            {
                "author_id": "1231059979844456448",
                "created_at": "2021-02-26T04:25:49.000Z",
                "id": "1365156089554067459",
                "text": "@KelleyALynch1 @marwilliamson @therecount @LindseyGrahamSC She's fine with that just as she's fine with Biden's Nazis in Ukraine. She wants war with Russia, too. She blocked me for this tweet because she couldn't even condemn Biden's Nazis in Ukraine. She's a fauxgressive warmonger, a wolf in sheep's clothing. \n[link here]"
            },
            {
                "author_id": "1315477593303310336",
                "created_at": "2021-02-23T00:00:41.000Z",
                "id": "1364002202843451399",
                "text": "@MistyKitty3 @BlairMurray83 @FrankAmari2 @LindseyGrahamSC \ud83e\udd23 Someone didn\u2019t like what I said and blocked me."
            },
            {
                "author_id": "79007230",
                "created_at": "2021-02-13T13:10:54.000Z",
                "id": "1360577189750702080",
                "text": "@Fuzzy_Fuzzbutt @DearAuntCrabby @LindseyGrahamSC I know you blocked me, poor little boo-boo feels attacked by a rhetorical question. But the reality is that cartoon is WILDLY homophobic."
            }
        ],
        "includes": {
            "media": [
                {
                    "media_key": "3_1361344652264280068",
                    "type": "photo",
                    "url": "[link here]"
                }
            ],
            "users": [
                {
                    "created_at": "2016-06-01T05:55:21.000Z",
                    "description": "Biden Inflation the worst in 30 years. His Handlers trying to Rebrand Brandon is Hilarious.",
                    "id": "737885223858384896",
                    "name": "Biden is a complete mess and you know it.",
                    "username": "zelda3024"
                },
                {
                    "created_at": "2017-03-31T00:54:05.000Z",
                    "description": "Love God, Love Family, Love Country, Love Freedom - if we put those things first everything else will be great. MAGA",
                    "id": "847612931487416323",
                    "name": "Joey Bagadonuts",
                    "username": "AmericanGr8ness"
                },
                {
                    "created_at": "2009-01-05T15:25:55.000Z",
                    "description": "small & local garlic farmer; independent American; old surfer dude; working to find and speak truth to power; \ud83c\uddfa\ud83c\uddf8; mahalo and Maluhia",
                    "id": "18634205",
                    "name": "MacGregorGarlic",
                    "username": "MacGregorGarlic"
                },
                {
                    "created_at": "2009-03-28T22:53:28.000Z",
                    "description": "Let's Go Darwin!",
                    "id": "27327319",
                    "name": "Karen Kennedy",
                    "username": "KayKay68"
                },
                {
                    "created_at": "2017-10-10T06:15:18.000Z",
                    "description": "Mom\ud83d\udc95Cannactivist\ud83c\udf3fSecularHumanist\ud83c\udf10 BLM\u270a\ud83c\udfff\ud83c\udf08Ally\ud83e\udd8bCPTSD\u2695\ufe0f FTD\ud83e\udd14MeToo\ud83c\udf38ProChoice\ud83d\udc93CRPS\ud83d\ude23ClimateChange\ud83c\udf0e DACA\ud83c\uddfa\ud83c\uddf2AdoptDontShop\ud83d\udc3e#Steelers \ud83d\udda4\ud83d\udc9b #Vaxxed2TheMax\u270a\ud83d\udc9a",
                    "id": "917634626247647232",
                    "name": "Raven The Hemptress #LegalizeGlobally\ud83d\udc9a\ud83c\udf3f\u267f",
                    "username": "Kraven_Raven24"
                },
                {
                    "created_at": "2020-02-22T03:35:56.000Z",
                    "description": "Monetarism is the underlying cause of our disease; human progress and peace through development is the cure. Eurasian integration will benefit all of humanity!",
                    "id": "1231059979844456448",
                    "name": "\ud83c\udd70pocalypsis \ud83c\udd70pocalypseos \u2014 BRI Is The Future",
                    "username": "apocalypseos"
                },
                {
                    "created_at": "2020-10-12T02:21:21.000Z",
                    "description": "Father of two beautiful boys. Believer in the Constitution of the United States. Protector of my own rights. #Meatatarian",
                    "id": "1315477593303310336",
                    "name": "\ud83e\udd85 Steven Duggin \u2665\ufe0f \ud83c\uddfa\ud83c\uddf8\ud83d\uddfd",
                    "username": "itsStevenDuggin"
                },
                {
                    "created_at": "2018-12-02T06:25:16.000Z",
                    "description": "",
                    "id": "1069115263671562240",
                    "name": "Barhag",
                    "username": "TheBarhag"
                },
                {
                    "created_at": "2020-09-08T13:19:17.000Z",
                    "description": "Not the liberals cup of tea",
                    "id": "1303321972227690496",
                    "name": "Christy",
                    "username": "Christy54177764"
                },
                {
                    "created_at": "2009-03-31T19:34:24.000Z",
                    "description": "NY-grown, FL-tanned, scribe, word nerd, TV junkie, game show champ, yenta, wife, twin mama, hot sauce collector, Bloody Mary maven &, says @NYPost, savvy gadfly",
                    "id": "27943005",
                    "name": "Lesley Abravanel",
                    "username": "lesleyabravanel"
                },
                {
                    "created_at": "2019-05-08T22:15:51.000Z",
                    "description": "\ud83c\udf37 Wholesome account dedicated to Yuuko Aioi. \ud83c\udf37\n\nI also enjoy making new friends and posting about games, my everyday life, cats, NASCAR, memes and fumos!",
                    "id": "1126249378279297027",
                    "name": "Vaxen #DailyYuuko \u2603\ufe0f",
                    "username": "YuukoEnjoyer"
                },
                {
                    "created_at": "2019-12-18T22:47:10.000Z",
                    "description": "The Republican party is bad for America. The Conservatives are Trump bootlickers who are afraid to stand up to him. This great nation is in serious trouble.",
                    "id": "1207432044390699008",
                    "name": "Angry Patriot",
                    "username": "AngryPatriot20"
                },
                {
                    "created_at": "2012-11-05T05:19:37.000Z",
                    "description": "Employment lawyer. Represent employers and employees. 30 years ago, my mentor told me to seek the truth as a lawyer. Still do that. Tweets are not legal advice.",
                    "id": "926909484",
                    "name": "Alfred Southerland",
                    "username": "TexasEEOLaw"
                },
                {
                    "created_at": "2009-10-01T21:17:18.000Z",
                    "description": "Knitter, IT PM, Mom/Wife, Dem, not-observant Jewish Boomer (Gen Jones). If you seem like a troll, have a locked acct or put me on a list, I'll \ud83d\udeab you.\n\nShe/her.",
                    "id": "79007230",
                    "name": "\u2721\ufe0f MG \u2721\ufe0f #DoYourPart #GetBoosted #MaskUp",
                    "username": "knitvspurl"
                }
            ]
        },
        "meta": {
            "newest_id": "1375567243082338314",
            "next_token": "b26v89c19zqg8o3fosnr8o52h2bpczky08inrqbn3ad8d",
            "oldest_id": "1360577189750702080",
            "result_count": 14
        }
    },
    {
        "data": [
            {
                "author_id": "1248251899884814336",
                "created_at": "2021-03-27T13:36:45.000Z",
                "id": "1375803982409576450",
                "text": "@gavinjeffries0 @steven86026859 @MSNBC @SenBooker Uh Oh our friend Steve blocked me, I guess not being able to answer your simple question and being asked to was too much for him."
            },
            {
                "author_id": "752266160352010241",
                "created_at": "2021-02-06T20:34:06.000Z",
                "id": "1358152008948195328",
                "text": "@fattypinner @tkbone32221 @SenSchumer @SenBooker @RonWyden He blocked me \ud83e\udd23\ud83d\ude2d\ud83e\udd23\ud83e\udd23\ud83e\udd23\ud83d\ude2d"
            },
            {
                "author_id": "70127580",
                "created_at": "2021-01-20T21:35:26.000Z",
                "id": "1352006847226671114",
                "text": "@HUMAN1TY_tweets @KMJeezy @fancytomboy Chile @SenBooker @CoryBooker is not playing.  Gurl he really trying hard to pull off straight.  @rosariodawson blocked me. . . .  Guess I touched a nerve. . . .  I thought she was Bi?  LOL \ud83d\ude02"
            },
            {
                "author_id": "386603314",
                "created_at": "2021-01-07T02:18:04.000Z",
                "id": "1347004547844096001",
                "text": "Lmao it was a few hours I just posted Cory Booker memes that nobody BUT HIM really saw and he blocked me that\u2019s what it was [link here]"
            },
            {
                "attachments": {
                    "media_keys": [
                        "3_1347003932875358217"
                    ]
                },
                "author_id": "386603314",
                "created_at": "2021-01-07T02:15:39.000Z",
                "id": "1347003935916052480",
                "text": "Remember when Cory Booker blocked me lol [link here]"
            },
            {
                "author_id": "1108691472214155265",
                "created_at": "2020-12-31T06:38:50.000Z",
                "id": "1344533452956295168",
                "text": "@DemToRose @CarolenaMatus @SavageJoyMarie1 @KamalaHarris @SenSchumer @SenKamalaHarris @SenBooker @SenFeinstein He blocked me - what\u2019d he say?"
            },
            {
                "attachments": {
                    "media_keys": [
                        "3_1340532486812549121",
                        "3_1340532486808297475"
                    ]
                },
                "author_id": "2706897311",
                "created_at": "2020-12-20T05:40:26.000Z",
                "id": "1340532491594153984",
                "text": "@NeaminZeleke @SenWarren @SenBooker @CornelWest It\u2019s very interesting. He(smgebru) posted the following on Instagram & I (si_feam) challenged him. He blocked me. He doesn\u2019t want to talk truth but only being propagandist for TPLF. [link here]"
            },
            {
                "author_id": "1293905938131251200",
                "created_at": "2020-12-19T02:13:30.000Z",
                "id": "1340118027937955841",
                "text": "@heatherklus @AwakenedJoyce @data_nerd @FriedrichHayek @RepYvetteClarke @alexleavitt @RonWyden @Google @sundarpichai @timnitGebru @RepAnnaEshoo @SenBooker @NydiaVelazquez @RepBillFoster @RepMcNerney @SenWarren Naturally, this know-nothing dilettante blocked me now. Which is the standard response of the #woke when they run out of arguments."
            },
            {
                "author_id": "1100925481803804673",
                "created_at": "2020-11-19T08:28:39.000Z",
                "id": "1329340801915228161",
                "text": "Not calling  @HerSpiritistheTruth45 a Democrat. She misread my meaning but then blocked me so if someone would let her know I was referring to Cory Booker, not her!!! [link here]"
            },
            {
                "author_id": "309190582",
                "created_at": "2020-11-17T17:45:40.000Z",
                "id": "1328756204626186242",
                "text": "@HillaryClinton See you soon I tried really hard to make the cut I couldn't do the election and Cory Booker sorry madam.  He was the issue with your campaign.  He blocked me so hard.  He killed my entire family.  \nMommy said she was dying so sorry I really hustle. \n\nRobinMichelle"
            },
            {
                "author_id": "1254067781621997572",
                "created_at": "2020-11-15T02:15:30.000Z",
                "id": "1327797342997766145",
                "text": "Reminds me of that time Cory Booker hopped in my DMs to argue about charter schools. He blocked me shortly there after."
            }
        ],
        "includes": {
            "media": [
                {
                    "media_key": "3_1358448920632909825",
                    "type": "photo",
                    "url": "[link here]"
                },
                {
                    "media_key": "3_1347003932875358217",
                    "type": "photo",
                    "url": "[link here]"
                },
                {
                    "media_key": "3_1340532486812549121",
                    "type": "photo",
                    "url": "[link here]"
                },
                {
                    "media_key": "3_1340532486808297475",
                    "type": "photo",
                    "url": "[link here]"
                }
            ],
            "users": [
                {
                    "created_at": "2020-04-09T14:11:04.000Z",
                    "description": "",
                    "id": "1248251899884814336",
                    "name": "Firstcomm",
                    "username": "Firstcomm1"
                },
                {
                    "created_at": "2011-05-04T19:26:22.000Z",
                    "description": "Cinephile, balletomane, book lover, tennis fan, K-Drama fanatic, Jang Na-ra fangirl, USC School of Cinematic Arts alumna, Hillary Clinton and Nancy Pelosi Dem.",
                    "id": "293104735",
                    "name": "Joyce Tyler",
                    "username": "joyce_tyler"
                },
                {
                    "created_at": "2011-09-27T14:50:37.000Z",
                    "description": "Spelman College, BA, George Washington University MA, University of South Florida Ph.D. in Political Science, proud Ted Kennedy, Obama, Biden/Harris Democrat!",
                    "id": "380970864",
                    "name": "Stephanie L. Williams, Ph.D.",
                    "username": "slwilliams1101"
                },
                {
                    "created_at": "2016-10-31T19:37:19.000Z",
                    "description": "Loves: life, fam, cats, cars, tattoos, reality TV; collector of t-shirts & Volkswagen\u2019s. Hates: Oxford commas. #CombatVet #Medic #BidenHarris2020 #Resist",
                    "id": "793175035322171397",
                    "name": "Que Sarah Sarah \ud83d\udda4",
                    "username": "sarahalli13"
                },
                {
                    "created_at": "2016-07-10T22:20:03.000Z",
                    "description": "3x Hollywood Video Street Fighter 2 Champion",
                    "id": "752266160352010241",
                    "name": "Sugarcoder",
                    "username": "TheSugarCoder"
                },
                {
                    "created_at": "2009-08-30T14:15:02.000Z",
                    "description": "",
                    "id": "70127580",
                    "name": "Michael J. Stratton",
                    "username": "mjstra"
                },
                {
                    "created_at": "2011-10-07T15:28:05.000Z",
                    "description": "host of @WeDidntDoIt true crime/comedy podcast | future true crime legend | audio engineer | comedian | retired mma fighter | bjj purple belt | #ReMeMber",
                    "id": "386603314",
                    "name": "\u02b0\u1d58\u207f\u1d4d \u1d34\u1d2c\u1d3a\u1d37 \uea00",
                    "username": "yunghank"
                },
                {
                    "created_at": "2019-03-21T11:27:00.000Z",
                    "description": "",
                    "id": "1108691472214155265",
                    "name": "lu",
                    "username": "lubean13"
                },
                {
                    "created_at": "2014-07-13T12:10:52.000Z",
                    "description": "Scie-Techie|Centrist|Prefer_Equilibrium|",
                    "id": "2706897311",
                    "name": "Mesthio\ud83c\uddea\ud83c\uddf9",
                    "username": "MEsthio"
                },
                {
                    "created_at": "2020-08-13T13:43:19.000Z",
                    "description": "Trump stans are just as idiotic as the woke.",
                    "id": "1293905938131251200",
                    "name": "Pen\u00e9lope",
                    "username": "Penlope56181829"
                },
                {
                    "created_at": "2019-02-28T01:07:43.000Z",
                    "description": "An earthen vessel sojourning through the adventures & challenges of life. Singer/songwriter, poet, artist.  Intercessor, worshiper, mystic. Mom, grannyX4.",
                    "id": "1100925481803804673",
                    "name": "AVessel",
                    "username": "AVessel2"
                },
                {
                    "created_at": "2011-06-01T17:48:10.000Z",
                    "description": "Publicist, Educator, Public Relations butterfly.  Newsroom & Communications Specialist dabbling in Politics and Entertainment rt not necessarily endorsement",
                    "id": "309190582",
                    "name": "RMC Communications PR",
                    "username": "RobinMCouch"
                },
                {
                    "created_at": "2020-04-25T15:21:03.000Z",
                    "description": "\u201cAll labor has dignity.\u201d- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I\u2019m just a blue collar dude from the D. @jbrous14",
                    "id": "1254067781621997572",
                    "name": "Ella Septima-Hamer",
                    "username": "jbrous41"
                }
            ]
        },
        "meta": {
            "newest_id": "1375803982409576450",
            "next_token": "b26v89c19zqg8o3fosbv3bjxj42w0zkak6xf94932g3ul",
            "oldest_id": "1327797342997766145",
            "result_count": 14
        }
    }
]

從中檢索資料json_response并將其保存的 代碼 df

# append data (author_id, created_at, tweet_id, text, bio, image_url) from json_response to a data frame
df = pd.DataFrame()

for each_dict in json_response:

    # 1. loop for data object
    for tweet in each_dict['data']:

        row = {} # empty dict for data

        row["author_id"] = tweet['author_id'] # 1. id of user
        row["created_at"] = dateutil.parser.parse(tweet['created_at'])  # 2. time of tweet
        row["tweet_id"] = tweet['id'] # 3. tweet id
        row["text"] = tweet['text'] # 4. tweet

        # 2. loop for user object
        for user in each_dict['includes']['users']:
            # 5. user bio
            if 'description' in user:
                row['bio'] = user.get('description') # if user has bio get bio
            else:
                row['bio'] = user.get(' ') # if user has no bio fill row with NaN

        # 3. loop for media object
        for media in each_dict['includes']['media']:
            # 6. image url
            if 'url' in media:
                row['image_url'] = media.get('url') # if user tweet url get url
            else:
                row['image_url'] = media.get(' ') # if user does not tweet url fill row with NaN

        df = df.append(row, ignore_index=True) # append data to empty df

上面代碼的結果。問題是 bioimage_url列包含每個中最后一個物件的重復項each_dict

    author_id                created_at             tweet_id                                                                                                                                                                                                                                                                                                                                                   text                                                                                                                                                                bio                                        image_url
0    737885223858384896 2021-03-26 21:56:02 00:00  1375567243082338314                                                                @hogan_1969 @LindseyGrahamSC LOL She Blocked me.. could not admit the truth could she now. okay so where is her source for the shirts? and that is what he said. I (quote) We immediately surge the border all those seeking asylum. What about his lie about the cages? no Answer lol.  Knitter, IT PM, Mom/Wife, Dem, not-observant Jewish Boomer (Gen Jones). If you seem like a troll, have a locked acct or put me on a list, I'll ?? you.\n\nShe/her. [link here]
1    847612931487416323 2021-03-26 21:55:24 00:00  1375567083791073283                                                                                                                                                                                                               @hogan_1969 @TeichTerry @thehill @LindseyGrahamSC @hogan_1969 just blocked me for showing her the actual numbers ??\n\n#LiberalsHateFacts  Knitter, IT PM, Mom/Wife, Dem, not-observant Jewish Boomer (Gen Jones). If you seem like a troll, have a locked acct or put me on a list, I'll ?? you.\n\nShe/her.  [link here]
2              18634205 2021-03-08 12:29:00 00:00  1368901564363051010                                                                                                       Huh.  Made me think if @LeaderMcConnell @LindseyGrahamSC @marcorubio @SenTedCruz feel trapped under the thumb of Trumpy.  And who else? @IvankaTrump? @MELANIATRUMP ? @DonaldJTrumpJr ? I’d say Eric, but he blocked me. [link here]  Knitter, IT PM, Mom/Wife, Dem, not-observant Jewish Boomer (Gen Jones). If you seem like a troll, have a locked acct or put me on a list, I'll ?? you.\n\nShe/her.  [link here]
3              27327319 2021-03-02 11:53:16 00:00  1366718245521211393                                                                                                                                                                                                                                @fedupinNHtoo @LindseyGrahamSC Exactly. I asked that question of a Republican on Facebook last night and she blocked me  Knitter, IT PM, Mom/Wife, Dem, not-observant Jewish Boomer (Gen Jones). If you seem like a troll, have a locked acct or put me on a list, I'll ?? you.\n\nShe/her.  [link here]
4    917634626247647232 2021-02-28 18:16:45 00:00  1366089974907432961                                                                                                                                                                        @gop this is for you! @tedcruz @LindseyGrahamSC @MittRomney @mikepompeo\n#BitchyMcC blocked me!??\nWatch "Jack Off Jill - Hypocrite   lyrics" on YouTube [link here]  Knitter, IT PM, Mom/Wife, Dem, not-observant Jewish Boomer (Gen Jones). If you seem like a troll, have a locked acct or put me on a list, I'll ?? you.\n\nShe/her.  [link here]
...
...
...                                                                                                                                                                                                        @DemToRose @CarolenaMatus @SavageJoyMarie1 @KamalaHarris @SenSchumer @SenKamalaHarris @SenBooker @SenFeinstein He blocked me - what’d he say?                           “All labor has dignity.”- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I’m just a blue collar dude from the D. @jbrous14  [link here]
23           2706897311 2020-12-20 05:40:26 00:00  1340532491594153984                                                                                      @NeaminZeleke @SenWarren @SenBooker @CornelWest It’s very interesting. He(smgebru) posted the following on Instagram & I (si_feam) challenged him. He blocked me. He doesn’t want to talk truth but only being propagandist for TPLF. [link here]                           “All labor has dignity.”- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I’m just a blue collar dude from the D. @jbrous14  [link here]
24  1293905938131251200 2020-12-19 02:13:30 00:00  1340118027937955841  @heatherklus @AwakenedJoyce @data_nerd @FriedrichHayek @RepYvetteClarke @alexleavitt @RonWyden @Google @sundarpichai @timnitGebru @RepAnnaEshoo @SenBooker @NydiaVelazquez @RepBillFoster @RepMcNerney @SenWarren Naturally, this know-nothing dilettante blocked me now. Which is the standard response of the #woke when they run out of arguments.                           “All labor has dignity.”- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I’m just a blue collar dude from the D. @jbrous14  [link here]
25  1100925481803804673 2020-11-19 08:28:39 00:00  1329340801915228161                                                                                                                                                         Not calling  @HerSpiritistheTruth45 a Democrat. She misread my meaning but then blocked me so if someone would let her know I was referring to Cory Booker, not her!!! [link here]                           “All labor has dignity.”- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I’m just a blue collar dude from the D. @jbrous14  [link here]
26            309190582 2020-11-17 17:45:40 00:00  1328756204626186242                                                            @HillaryClinton See you soon I tried really hard to make the cut I couldn't do the election and Cory Booker sorry madam.  He was the issue with your campaign.  He blocked me so hard.  He killed my entire family.  \nMommy said she was dying so sorry I really hustle. \n\nRobinMichelle                           “All labor has dignity.”- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I’m just a blue collar dude from the D. @jbrous14  [link here]
27  1254067781621997572 2020-11-15 02:15:30 00:00  1327797342997766145                                                                                                                                                                                                                                Reminds me of that time Cory Booker hopped in my DMs to argue about charter schools. He blocked me shortly there after.                           “All labor has dignity.”- MLK Ronald Reagan is the devil. Bill Clinton screwed us all. I’m just a blue collar dude from the D. @jbrous14  [link here]

uj5u.com熱心網友回復:

您只是在檢查 bio 的描述是否存在,
您還必須檢查此描述是否屬于當前用戶。
這應該適用于 bio & 同樣應該適用于 image_url。

 # 2. loop for user object
        row['bio']=None # assuming user has no bio
        for user in each_dict['includes']['users']:
            # 5. user bio
            # check for bio of the current user only
            if 'description' in user and user['id']==tweet['author_id']:
                row['bio'] = user.get('description') # if user has bio get bio
                break # break the loop, as user bio is found
               
        

uj5u.com熱心網友回復:

如何處理 bio 和 image_url 不是很清楚。但是另一種方法是查看合并

dataList=[]
usersList=[]
for j  in jsonData:
    dataList.append(pd.DataFrame(j['data']))
    usersList.append(pd.DataFrame(j['includes']['users']))

data=pd.concat(dataList)
users=pd.concat(usersList)
mergedData=data.merge(users, how='left',left_on='id',right_on='id')#aaply suitable logic as desired for media

轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/420721.html

標籤:

上一篇:根據另一個陣列值過濾兩個陣列,并將不可用的值推送到另一個陣列中

下一篇:for回圈忽略第一項python

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • 面試突擊第一季,第二季,第三季

    第一季必考 https://www.bilibili.com/video/BV1FE411y79Y?from=search&seid=15921726601957489746 第二季分布式 https://www.bilibili.com/video/BV13f4y127ee/?spm_id_fro ......

    uj5u.com 2020-09-10 05:35:24 more
  • 第三單元作業總結

    1.前言 這應該是本學期最后一次寫作業總結了吧。總體來說,對作業的節奏也差不多掌握了,作業做起來的效率也更高了。雖然和之前的作業一樣,作業中都要用到新的知識,但是相比之前,更加懂得了如何利用工具以及資料。雖然之間卡過殼,但總體而言,這幾次作業還算完成的比較好。 2.作業程序總結 相比前兩個單元,此單 ......

    uj5u.com 2020-09-10 05:35:41 more
  • 北航OO(2020)第四單元博客作業暨課程總結博客

    北航OO(2020)第四單元博客作業暨課程總結博客 本單元作業的架構設計 在本單元中,由于UML圖具有比較清晰的樹形結構,因此我對其中需要進行查詢操作的元素進行了包裝,在樹的父節點中存盤所有孩子的參考。考慮到性能問題,我采用了快取機制,一次查詢后盡可能快取已經遍歷過的資訊,以減少遍歷次數。 本單元我 ......

    uj5u.com 2020-09-10 05:35:48 more
  • BUAA_OO_第四單元

    一、UML決議器設計 ? 先看下題目:第四單元實作一個基于JDK 8帶有效性檢查的UML(Unified Modeling Language)類圖,順序圖,狀態圖分析器 MyUmlInteraction,實際上我們要建立一個有向圖模型,UML中的物件(元素)可能與同級元素連接,也可與低級元素相連形成 ......

    uj5u.com 2020-09-10 05:35:54 more
  • 6.1邏輯運算子

    邏輯運算子 1. && 短路與 運算式1 && 運算式2 01.運算式1為true并且運算式2也為true 整體回傳為true 02.運算式1為false,將不會執行運算式2 整體回傳為false 03.只要有一個運算式為false 整體回傳為false 2. || 短路或 運算式1 || 運算式2 ......

    uj5u.com 2020-09-10 05:35:56 more
  • BUAAOO 第四單元 & 課程總結

    1. 第四單元:StarUml檔案決議 本單元采用了圖模型決議UML。 UML檔案可以抽象為圖、子圖、邊的邏輯結構。 在實作中,圖的節點包括類、介面、屬性,子圖包括狀態圖、順序圖等。 采用了三次遍歷UML元素的方法建圖,第一遍遍歷建點,第二、三次遍歷設定屬性、連邊,實作圖物件的初始化。這里借鑒了一些 ......

    uj5u.com 2020-09-10 05:36:06 more
  • 談談我對C# 多型的理解

    面向物件三要素:封裝、繼承、多型。 封裝和繼承,這兩個比較好理解,但要理解多型的話,可就稍微有點難度了。今天,我們就來講講多型的理解。 我們應該經常會看到面試題目:請談談對多型的理解。 其實呢,多型非常簡單,就一句話:呼叫同一種方法產生了不同的結果。 具體實作方式有三種。 一、多載 多載很簡單。 p ......

    uj5u.com 2020-09-10 05:36:09 more
  • Python 資料驅動工具:DDT

    背景 python 的unittest 沒有自帶資料驅動功能。 所以如果使用unittest,同時又想使用資料驅動,那么就可以使用DDT來完成。 DDT是 “Data-Driven Tests”的縮寫。 資料:http://ddt.readthedocs.io/en/latest/ 使用方法 dd. ......

    uj5u.com 2020-09-10 05:36:13 more
  • Python里面的xlrd模塊詳解

    那我就一下面積個問題對xlrd模塊進行學習一下: 1.什么是xlrd模塊? 2.為什么使用xlrd模塊? 3.怎樣使用xlrd模塊? 1.什么是xlrd模塊? ?python操作excel主要用到xlrd和xlwt這兩個庫,即xlrd是讀excel,xlwt是寫excel的庫。 今天就先來說一下xl ......

    uj5u.com 2020-09-10 05:36:28 more
  • 當我們創建HashMap時,底層到底做了什么?

    jdk1.7中的底層實作程序(底層基于陣列+鏈表) 在我們new HashMap()時,底層創建了默認長度為16的一維陣列Entry[ ] table。當我們呼叫map.put(key1,value1)方法向HashMap里添加資料的時候: 首先,呼叫key1所在類的hashCode()計算key1 ......

    uj5u.com 2020-09-10 05:36:38 more
最新发布
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:20:47 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:20:25 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:20:17 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:20:10 more
  • 【中介者設計模式詳解】C/Java/JS/Go/Python/TS不同語言實作

    * 中介者模式是一種行為型設計模式,它可以用來減少類之間的直接依賴關系,
    * 將物件之間的通信封裝到一個中介者物件中,從而使得各個物件之間的關系更加松散。
    * 在中介者模式中,物件之間不再直接相互互動,而是通過中介者來中轉訊息。 ......

    uj5u.com 2023-04-20 08:19:44 more
  • 露天煤礦現場調研和交流案例分享

    他們集團的資訊化公司及研究院在一個礦區正在做智能礦山的統一平臺的 試點,專案投資大概1億,包括了礦山的各方面的內容,顯示得我們這次交流有點多余。他們2年前開始做智能礦山的規劃,有很多煤礦行業專家的加持,他們的描述是非常完美,但是去年底應該上線的平臺,現在還沒有看到影子。他們確實有很多場景需求,但是被... ......

    uj5u.com 2023-04-20 08:19:07 more
  • 《社區人員管理》實戰案例設計&個人案例分享

    設計是一個讓人夢想成真程序,開始編碼、測驗、除錯之前進行需求分析和架構設計,才能保證關鍵方面都做正確 ......

    uj5u.com 2023-04-20 08:18:57 more
  • 軟體架構生態化-多角色交付的探索實踐

    作為一個技術架構師,不僅僅要緊跟行業技術趨勢,還要結合研發團隊現狀及痛點,探索新的交付方案。在日常中,你是否遇到如下問題 “ 業務需求排期長研發是瓶頸;非研發角色感受不到研發技改提效的變化;引入ISV 團隊又擔心質量和安全,培訓周期長“等等,基于此我們探索了一種新的技術體系及交付方案來解決如上問題。 ......

    uj5u.com 2023-04-20 08:18:49 more
  • 05單件模式

    #經典的單件模式 public class Singleton { private static Singleton uniqueInstance; //一個靜態變數持有Singleton類的唯一實體。 // 其他有用的實體變數寫在這里 //構造器宣告為私有,只有Singleton可以實體化這個類! ......

    uj5u.com 2023-04-19 08:42:51 more
  • 【架構與設計】常見微服務分層架構的區別和落地實踐

    軟體工程的方方面面都遵循一個最基本的道理:沒有銀彈,架構分層模型更是如此,每一種都有各自優缺點,所以請根據不同的業務場景,并遵循簡單、可演進這兩個重要的架構原則選擇合適的架構分層模型即可。 ......

    uj5u.com 2023-04-19 08:42:41 more