Separte Pandas df进入单独的表格

时间:2018-08-09 21:05:00

标签: python python-3.x pandas dataframe

我有一张下表(pandas-data-frame),我想将“时间”,“温度”,“天气”等...分开到单独的列中。

    Conditions
    Comfort
February 1, 2016    [{'Time': '12:58 amMon, Feb 1', 'Temp': '50°F', 'Weather': 'Light rain. Mostly cloudy.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '88%', 'Visibility': '29.79 "Hg'}, {'Time': '1:58 am', 'Temp': '46°F', 'Weather': 'Mostly cloudy.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.82 "Hg'}, {'Time': '2:58 am', 'Temp': '43°F', 'Weather': 'Mostly cloudy.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '85%', 'Visibility': '29.87 "Hg'}, {'Time': '3:58 am', 'Temp': '42°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.89 "Hg'}, {'Time': '4:58 am', 'Temp': '41°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '82%', 'Visibility': '29.91 "Hg'}, {'Time': '5:58 am', 'Temp': '39°F', 'Weather': 'Mostly cloudy.', 'Wind': '8 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.93 "Hg'}, {'Time': '6:58 am', 'Temp': '38°F', 'Weather': 'Partly cloudy.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '82%', 'Visibility': '29.96 "Hg'}, {'Time': '7:58 am', 'Temp': '38°F', 'Weather': 'Partly sunny.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '80%', 'Visibility': '29.99 "Hg'}, {'Time': '8:58 am', 'Temp': '38°F', 'Weather': 'Overcast.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '78%', 'Visibility': '30.01 "Hg'}, {'Time': '9:58 am', 'Temp': '40°F', 'Weather': 'Broken clouds.', 'Wind': '7 mph', 'Humidity': '↑', 'Barometer': 'N/A', 'Visibility': '30.01 "Hg'}, {'Time': '10:58 am', 'Temp': '41°F', 'Weather': 'Broken clouds.', 'Wind': '1 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '30.02 "Hg'}, {'Time': '11:58 am', 'Temp': '41°F', 'Weather': 'Partly sunny.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '70%', 'Visibility': '30.04 "Hg'}, {'Time': '12:58 pm', 'Temp': '42°F', 'Weather': 'Scattered clouds.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '69%', 'Visibility': '30.04 "Hg'}, {'Time': '1:58 pm', 'Temp': '43°F', 'Weather': 'Partly sunny.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.03 "Hg'}, {'Time': '2:58 pm', 'Temp': '44°F', 'Weather': 'Partly sunny.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '62%', 'Visibility': '30.02 "Hg'}, {'Time': '3:58 pm', 'Temp': '46°F', 'Weather': 'Passing clouds.', 'Wind': '6 mph', 'Humidity': '↑', 'Barometer': '58%', 'Visibility': '30.03 "Hg'}, {'Time': '4:58 pm', 'Temp': '46°F', 'Weather': 'Sunny.', 'Wind': '6 mph', 'Humidity': '↑', 'Barometer': '57%', 'Visibility': '30.04 "Hg'}, {'Time': '5:58 pm', 'Temp': '43°F', 'Weather': 'Clear.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.06 "Hg'}, {'Time': '6:58 pm', 'Temp': '39°F', 'Weather': 'Clear.', 'Wind': '1 mph', 'Humidity': '↑', 'Barometer': '71%', 'Visibility': '30.09 "Hg'}, {'Time': '7:58 pm', 'Temp': '35°F', 'Weather': 'Clear.', 'Wind': '1 mph', 'Humidity': '↑', 'Barometer': '79%', 'Visibility': '30.11 "Hg'}, {'Time': '8:58 pm', 'Temp': '32°F', 'Weather': 'Clear.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '85%', 'Visibility': '30.13 "Hg'}, {'Time': '9:58 pm', 'Temp': '30°F', 'Weather': 'Clear.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '91%', 'Visibility': '30.14 "Hg'}, {'Time': '10:58 pm', 'Temp': '28°F', 'Weather': 'Clear.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '93%', 'Visibility': '30.14 "Hg'}, {'Time': '11:58 pm', 'Temp': '29°F', 'Weather': 'Clear.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '90%', 'Visibility': '30.13 "Hg'}]
February 10, 2016   [{'Time': '12:58 amWed, Feb 10', 'Temp': '17°F', 'Weather': 'Mostly cloudy.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '29.91 "Hg'}, {'Time': '1:58 am', 'Temp': '15°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '29.91 "Hg'}, {'Time': '2:58 am', 'Temp': '15°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '29.92 "Hg'}, {'Time': '4:58 am', 'Temp': '15°F', 'Weather': 'Light snow. Overcast.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '82%', 'Visibility': '29.93 "Hg'}, {'Time': '5:58 am', 'Temp': '15°F', 'Weather': 'Light snow. Mostly cloudy.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.93 "Hg'}, {'Time': '6:58 am', 'Temp': '15°F', 'Weather': 'Light snow. Overcast.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '82%', 'Visibility': '29.95 "Hg'}, {'Time': '7:58 am', 'Temp': '15°F', 'Weather': 'Light snow. Overcast.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '79%', 'Visibility': '29.96 "Hg'}, {'Time': '8:58 am', 'Temp': '15°F', 'Weather': 'Light snow. Overcast.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '81%', 'Visibility': '29.98 "Hg'}, {'Time': '9:58 am', 'Temp': '16°F', 'Weather': 'Light snow. Overcast.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '77%', 'Visibility': '29.99 "Hg'}, {'Time': '10:58 am', 'Temp': '17°F', 'Weather': 'Light snow. Cloudy.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '75%', 'Visibility': '30.01 "Hg'}, {'Time': '11:58 am', 'Temp': '17°F', 'Weather': 'Light snow. Overcast.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '74%', 'Visibility': '30.02 "Hg'}, {'Time': '12:58 pm', 'Temp': '18°F', 'Weather': 'Light snow. Overcast.', 'Wind': '17 mph', 'Humidity': '↑', 'Barometer': '77%', 'Visibility': '30.01 "Hg'}, {'Time': '1:58 pm', 'Temp': '18°F', 'Weather': 'Overcast.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '67%', 'Visibility': '30.02 "Hg'}, {'Time': '2:58 pm', 'Temp': '17°F', 'Weather': 'Light snow. Mostly cloudy.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '69%', 'Visibility': '30.02 "Hg'}, {'Time': '3:58 pm', 'Temp': '16°F', 'Weather': 'Mostly cloudy.', 'Wind': '18 mph', 'Humidity': '↑', 'Barometer': '67%', 'Visibility': '30.03 "Hg'}, {'Time': '4:58 pm', 'Temp': '16°F', 'Weather': 'Overcast.', 'Wind': '16 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.06 "Hg'}, {'Time': '5:58 pm', 'Temp': '15°F', 'Weather': 'Light snow. Overcast.', 'Wind': '17 mph', 'Humidity': '↑', 'Barometer': '71%', 'Visibility': '30.08 "Hg'}, {'Time': '6:58 pm', 'Temp': '14°F', 'Weather': 'Overcast.', 'Wind': '16 mph', 'Humidity': '↑', 'Barometer': '73%', 'Visibility': '30.11 "Hg'}, {'Time': '7:58 pm', 'Temp': '15°F', 'Weather': 'Overcast.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '67%', 'Visibility': '30.11 "Hg'}, {'Time': '8:58 pm', 'Temp': '13°F', 'Weather': 'Passing clouds.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.14 "Hg'}, {'Time': '9:58 pm', 'Temp': '13°F', 'Weather': 'Passing clouds.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '64%', 'Visibility': '30.14 "Hg'}, {'Time': '10:58 pm', 'Temp': '13°F', 'Weather': 'Passing clouds.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '64%', 'Visibility': '30.15 "Hg'}, {'Time': '11:58 pm', 'Temp': '12°F', 'Weather': 'Passing clouds.', 'Wind': '9 mph', 'Humidity': '↑', 'Barometer': '64%', 'Visibility': '30.15 "Hg'}]
February 11, 2016   [{'Time': '12:58 amThu, Feb 11', 'Temp': '11°F', 'Weather': 'Clear.', 'Wind': '7 mph', 'Humidity': '↑', 'Barometer': '66%', 'Visibility': '30.16 "Hg'}, {'Time': '1:58 am', 'Temp': '9°F', 'Weather': 'Clear.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '69%', 'Visibility': '30.16 "Hg'}, {'Time': '2:58 am', 'Temp': '8°F', 'Weather': 'Passing clouds.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '75%', 'Visibility': '30.17 "Hg'}, {'Time': '3:58 am', 'Temp': '8°F', 'Weather': 'Passing clouds.', 'Wind': '8 mph', 'Humidity': '↑', 'Barometer': '77%', 'Visibility': '30.19 "Hg'}, {'Time': '4:58 am', 'Temp': '6°F', 'Weather': 'Passing clouds.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '81%', 'Visibility': '30.20 "Hg'}, {'Time': '5:58 am', 'Temp': '8°F', 'Weather': 'Passing clouds.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '84%', 'Visibility': '30.22 "Hg'}, {'Time': '6:58 am', 'Temp': '7°F', 'Weather': 'Passing clouds.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '87%', 'Visibility': '30.25 "Hg'}, {'Time': '7:58 am', 'Temp': '8°F', 'Weather': 'Scattered clouds.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '87%', 'Visibility': '30.28 "Hg'}, {'Time': '8:58 am', 'Temp': '9°F', 'Weather': 'Partly sunny.', 'Wind': '6 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '30.30 "Hg'}, {'Time': '9:58 am', 'Temp': '14°F', 'Weather': 'Overcast.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '74%', 'Visibility': '30.32 "Hg'}, {'Time': '10:58 am', 'Temp': '18°F', 'Weather': 'Partly sunny.', 'Wind': '9 mph', 'Humidity': '↑', 'Barometer': '61%', 'Visibility': '30.31 "Hg'}, {'Time': '11:58 am', 'Temp': '20°F', 'Weather': 'Partly sunny.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '57%', 'Visibility': '30.31 "Hg'}, {'Time': '12:58 pm', 'Temp': '21°F', 'Weather': 'Overcast.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '48%', 'Visibility': '30.30 "Hg'}, {'Time': '1:58 pm', 'Temp': '22°F', 'Weather': 'Partly sunny.', 'Wind': '7 mph', 'Humidity': '↑', 'Barometer': '48%', 'Visibility': '30.29 "Hg'}, {'Time': '2:58 pm', 'Temp': '23°F', 'Weather': 'Overcast.', 'Wind': '9 mph', 'Humidity': '↑', 'Barometer': '47%', 'Visibility': '30.30 "Hg'}, {'Time': '3:58 pm', 'Temp': '22°F', 'Weather': 'Overcast.', 'Wind': '6 mph', 'Humidity': '↑', 'Barometer': '49%', 'Visibility': '30.31 "Hg'}, {'Time': '4:58 pm', 'Temp': '22°F', 'Weather': 'Overcast.', 'Wind': '8 mph', 'Humidity': '↑', 'Barometer': '50%', 'Visibility': '30.32 "Hg'}, {'Time': '5:58 pm', 'Temp': '21°F', 'Weather': 'Partly sunny.', 'Wind': '8 mph', 'Humidity': '↑', 'Barometer': '51%', 'Visibility': '30.33 "Hg'}, {'Time': '6:58 pm', 'Temp': '20°F', 'Weather': 'Overcast.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '50%', 'Visibility': '30.34 "Hg'}, {'Time': '7:58 pm', 'Temp': '18°F', 'Weather': 'Passing clouds.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '57%', 'Visibility': '30.36 "Hg'}, {'Time': '8:58 pm', 'Temp': '17°F', 'Weather': 'Passing clouds.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '64%', 'Visibility': '30.34 "Hg'}, {'Time': '9:58 pm', 'Temp': '14°F', 'Weather': 'Passing clouds.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '70%', 'Visibility': '30.34 "Hg'}, {'Time': '10:58 pm', 'Temp': '14°F', 'Weather': 'Passing clouds.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '75%', 'Visibility': '30.33 "Hg'}, {'Time': '11:58 pm', 'Temp': '14°F', 'Weather': 'Clear.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '71%', 'Visibility': '30.27 "Hg'}]
February 12, 2016   [{'Time': '12:58 amFri, Feb 12', 'Temp': '12°F', 'Weather': 'Clear.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '73%', 'Visibility': '30.31 "Hg'}, {'Time': '1:58 am', 'Temp': '10°F', 'Weather': 'Clear.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '78%', 'Visibility': '30.29 "Hg'}, {'Time': '2:58 am', 'Temp': '10°F', 'Weather': 'Clear.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '80%', 'Visibility': '30.28 "Hg'}, {'Time': '3:58 am', 'Temp': '10°F', 'Weather': 'Clear.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '78%', 'Visibility': '30.26 "Hg'}, {'Time': '4:58 am', 'Temp': '11°F', 'Weather': 'Mostly cloudy.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '79%', 'Visibility': '30.24 "Hg'}, {'Time': '5:58 am', 'Temp': '12°F', 'Weather': 'Mostly cloudy.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '77%', 'Visibility': '30.24 "Hg'}, {'Time': '6:58 am', 'Temp': '14°F', 'Weather': 'Passing clouds.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '75%', 'Visibility': '30.22 "Hg'}, {'Time': '7:58 am', 'Temp': '13°F', 'Weather': 'Partly sunny.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '75%', 'Visibility': '30.21 "Hg'}, {'Time': '8:58 am', 'Temp': '16°F', 'Weather': 'Cloudy.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '68%', 'Visibility': '30.21 "Hg'}, {'Time': '9:58 am', 'Temp': '19°F', 'Weather': 'Overcast.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '60%', 'Visibility': '30.19 "Hg'}, {'Time': '10:58 am', 'Temp': '23°F', 'Weather': 'Mostly cloudy.', 'Wind': '9 mph', 'Humidity': '↑', 'Barometer': '55%', 'Visibility': '30.18 "Hg'}, {'Time': '11:58 am', 'Temp': '24°F', 'Weather': 'Overcast.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '56%', 'Visibility': '30.16 "Hg'}, {'Time': '12:58 pm', 'Temp': '25°F', 'Weather': 'Mostly cloudy.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '54%', 'Visibility': '30.13 "Hg'}, {'Time': '1:59 pm', 'Temp': '25°F', 'Weather': 'More clouds than sun.', 'Wind': '16 mph', 'Humidity': '↑', 'Barometer': '54%', 'Visibility': '30.05 "Hg'}, {'Time': '2:58 pm', 'Temp': '26°F', 'Weather': 'Partly sunny.', 'Wind': '18 mph', 'Humidity': '↑', 'Barometer': '53%', 'Visibility': '30.09 "Hg'}, {'Time': '3:58 pm', 'Temp': '26°F', 'Weather': 'Overcast.', 'Wind': '17 mph', 'Humidity': '↑', 'Barometer': '56%', 'Visibility': '30.09 "Hg'}, {'Time': '4:58 pm', 'Temp': '26°F', 'Weather': 'Light snow. Broken clouds.', 'Wind': '16 mph', 'Humidity': '↑', 'Barometer': '66%', 'Visibility': '30.11 "Hg'}, {'Time': '5:56 pm', 'Temp': '25°F', 'Weather': 'Light snow. Partly sunny.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '74%', 'Visibility': '30.07 "Hg'}, {'Time': '5:58 pm', 'Temp': '24°F', 'Weather': 'Light snow. Partly sunny.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '80%', 'Visibility': '30.12 "Hg'}, {'Time': '6:58 pm', 'Temp': '22°F', 'Weather': 'Light snow. Partly cloudy.', 'Wind': '22 mph', 'Humidity': '↑', 'Barometer': '74%', 'Visibility': '30.16 "Hg'}, {'Time': '7:58 pm', 'Temp': '21°F', 'Weather': 'Light snow. Passing clouds.', 'Wind': '15 mph', 'Humidity': '↑', 'Barometer': '63%', 'Visibility': '30.21 "Hg'}, {'Time': '8:58 pm', 'Temp': '20°F', 'Weather': 'Passing clouds.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '57%', 'Visibility': '30.23 "Hg'}, {'Time': '9:58 pm', 'Temp': '18°F', 'Weather': 'Passing clouds.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '58%', 'Visibility': '30.26 "Hg'}, {'Time': '10:58 pm', 'Temp': '17°F', 'Weather': 'Clear.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.28 "Hg'}, {'Time': '11:58 pm', 'Temp': '16°F', 'Weather': 'Passing clouds.', 'Wind': '16 mph', 'Humidity': '↑', 'Barometer': '62%', 'Visibility': '30.31 "Hg'}]

因此,某天的行值(即2月1日)为:

February 1, 2016    [{'Time': '12:58 amMon, Feb 1', 'Temp': '50°F', 'Weather': 'Light rain. Mostly cloudy.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '88%', 'Visibility': '29.79 "Hg'}, {'Time': '1:58 am', 'Temp': '46°F', 'Weather': 'Mostly cloudy.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.82 "Hg'}, {'Time': '2:58 am', 'Temp': '43°F', 'Weather': 'Mostly cloudy.', 'Wind': '14 mph', 'Humidity': '↑', 'Barometer': '85%', 'Visibility': '29.87 "Hg'}, {'Time': '3:58 am', 'Temp': '42°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.89 "Hg'}, {'Time': '4:58 am', 'Temp': '41°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '82%', 'Visibility': '29.91 "Hg'}, {'Time': '5:58 am', 'Temp': '39°F', 'Weather': 'Mostly cloudy.', 'Wind': '8 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.93 "Hg'}, {'Time': '6:58 am', 'Temp': '38°F', 'Weather': 'Partly cloudy.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '82%', 'Visibility': '29.96 "Hg'}, {'Time': '7:58 am', 'Temp': '38°F', 'Weather': 'Partly sunny.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '80%', 'Visibility': '29.99 "Hg'}, {'Time': '8:58 am', 'Temp': '38°F', 'Weather': 'Overcast.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '78%', 'Visibility': '30.01 "Hg'}, {'Time': '9:58 am', 'Temp': '40°F', 'Weather': 'Broken clouds.', 'Wind': '7 mph', 'Humidity': '↑', 'Barometer': 'N/A', 'Visibility': '30.01 "Hg'}, {'Time': '10:58 am', 'Temp': '41°F', 'Weather': 'Broken clouds.', 'Wind': '1 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '30.02 "Hg'}, {'Time': '11:58 am', 'Temp': '41°F', 'Weather': 'Partly sunny.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '70%', 'Visibility': '30.04 "Hg'}, {'Time': '12:58 pm', 'Temp': '42°F', 'Weather': 'Scattered clouds.', 'Wind': '2 mph', 'Humidity': '↑', 'Barometer': '69%', 'Visibility': '30.04 "Hg'}, {'Time': '1:58 pm', 'Temp': '43°F', 'Weather': 'Partly sunny.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.03 "Hg'}, {'Time': '2:58 pm', 'Temp': '44°F', 'Weather': 'Partly sunny.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '62%', 'Visibility': '30.02 "Hg'}, {'Time': '3:58 pm', 'Temp': '46°F', 'Weather': 'Passing clouds.', 'Wind': '6 mph', 'Humidity': '↑', 'Barometer': '58%', 'Visibility': '30.03 "Hg'}, {'Time': '4:58 pm', 'Temp': '46°F', 'Weather': 'Sunny.', 'Wind': '6 mph', 'Humidity': '↑', 'Barometer': '57%', 'Visibility': '30.04 "Hg'}, {'Time': '5:58 pm', 'Temp': '43°F', 'Weather': 'Clear.', 'Wind': '3 mph', 'Humidity': '↑', 'Barometer': '65%', 'Visibility': '30.06 "Hg'}, {'Time': '6:58 pm', 'Temp': '39°F', 'Weather': 'Clear.', 'Wind': '1 mph', 'Humidity': '↑', 'Barometer': '71%', 'Visibility': '30.09 "Hg'}, {'Time': '7:58 pm', 'Temp': '35°F', 'Weather': 'Clear.', 'Wind': '1 mph', 'Humidity': '↑', 'Barometer': '79%', 'Visibility': '30.11 "Hg'}, {'Time': '8:58 pm', 'Temp': '32°F', 'Weather': 'Clear.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '85%', 'Visibility': '30.13 "Hg'}, {'Time': '9:58 pm', 'Temp': '30°F', 'Weather': 'Clear.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '91%', 'Visibility': '30.14 "Hg'}, {'Time': '10:58 pm', 'Temp': '28°F', 'Weather': 'Clear.', 'Wind': '5 mph', 'Humidity': '↑', 'Barometer': '93%', 'Visibility': '30.14 "Hg'}, {'Time': '11:58 pm', 'Temp': '29°F', 'Weather': 'Clear.', 'Wind': 'No wind', 'Humidity': '↑', 'Barometer': '90%', 'Visibility': '30.13 "Hg'}]

最终所需的结果如下所示(每月的每一天):

 barometer    humidity  temp     time    visibility weather  wind
0   30.00 "Hg   76%     36 °F   12:58 am    10 mi   Clear.  No wind
1   30.00 "Hg   80%     35 °F   1:58 am     10 mi   Clear.  2 mph
2   29.97 "Hg   79%     35 °F   2:58 am     10 mi   Clear.  2 mph
3   29.95 "Hg   88%     31 °F   3:58 am     10 mi   Clear.  3 mph
4   29.94 "Hg   90%     30 °F   4:58 am     10 mi   Clear.  3 mph
5   29.95 "Hg   92%     30 °F   5:58 am     10 mi   Clear.  2 mph
6   29.93 "Hg   86%     31 °F   6:58 am     10 mi   Clear.  2 mph
7   29.92 "Hg   94%     33 °F   7:58 am     10 mi   Sunny.  1 mph
8   29.88 "Hg   71%     42 °F   8:58 am     10 mi   Sunny.  6 mph
9   29.82 "Hg   61%     47 °F   9:58 am     10 mi   Sunny.  7 mph
10  29.79 "Hg   48%     52 °F   10:58 am    10 mi   P.sunny. 8 mph 

我将申请一个简短的代码。

注意:“湿度”后有类似“↑”的箭头,可以将其添加到单独的列中,称为(风向)。

这是Jupyter笔记本中的外观: enter image description here

1 个答案:

答案 0 :(得分:1)

因此,您有一个Series,其中包含描述某天信息的字典列表。 Series是表的第二列。为了简单起见,我仅使用几行:

data = pd.Series([
[{'Time': '12:58 amMon, Feb 1', 'Temp': '50°F', 'Weather': 'Light rain. Mostly cloudy.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '88%', 'Visibility': '29.79 "Hg'},{'Time': '1:58 am', 'Temp': '46°F', 'Weather': 'Mostly cloudy.', 'Wind': '12 mph', 'Humidity': '↑', 'Barometer': '83%', 'Visibility': '29.82 "Hg'}],
[{'Time': '12:58 amWed, Feb 10', 'Temp': '17°F', 'Weather': 'Mostly cloudy.', 'Wind': '13 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '29.91 "Hg'}, {'Time': '1:58 am', 'Temp': '15°F', 'Weather': 'Mostly cloudy.', 'Wind': '10 mph', 'Humidity': '↑', 'Barometer': '72%', 'Visibility': '29.91 "Hg'}]])

它看起来像:

0    [{'Time': '12:58 amMon, Feb 1', 'Temp': '50°F'...
1    [{'Time': '12:58 amWed, Feb 10', 'Temp': '17°F...

现在,我想将Series的字典列表展平为Series的字典:

from itertools import chain

flatten = list(chain.from_iterable(data))

然后构造结果数据框:

result = pd.DataFrame(flatten)

外观如下:

  Barometer Humidity  Temp   ...   Visibility                     Weather    Wind
0       88%        ↑  50°F   ...    29.79 "Hg  Light rain. Mostly cloudy.  13 mph
1       83%        ↑  46°F   ...    29.82 "Hg              Mostly cloudy.  12 mph
2       72%        ↑  17°F   ...    29.91 "Hg              Mostly cloudy.  13 mph
3       72%        ↑  15°F   ...    29.91 "Hg              Mostly cloudy.  10 mph

[4 rows x 7 columns]

对整个数据集执行相同的操作,并开心!