我有以下数据框:
Madrugada Mañana Tarde Noche
Lunes 1 2 3 4
Martes 5 6 7 8
Miércoles 9 10 11 12
Jueves 13 14 15 16
Viernes 17 18 19 20
Sábado 21 22 23 24
Domingo 25 26 27 28
创建于:
import pandas as pd
index = ['Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado', 'Domingo']
columns = ['Madrugada','Mañana', 'Tarde', 'Noche']
Cuadro = pd.DataFrame(index=index, columns=columns)
Cuadro.loc['Lunes'] = pd.Series({'Madrugada':1, 'Mañana':2, 'Tarde':3,
'Noche':4})
Cuadro.loc['Martes'] = pd.Series({'Madrugada':5, 'Mañana':6, 'Tarde':7,
'Noche':8})
Cuadro.loc['Miércoles'] = pd.Series({'Madrugada':9, 'Mañana':10, 'Tarde':11,
'Noche':12})
Cuadro.loc['Jueves'] = pd.Series({'Madrugada':13, 'Mañana':14, 'Tarde':15,
'Noche':16})
Cuadro.loc['Viernes'] = pd.Series({'Madrugada':17, 'Mañana':18, 'Tarde':19,
'Noche':20})
Cuadro.loc['Sábado'] = pd.Series({'Madrugada':21, 'Mañana':22, 'Tarde':23,
'Noche':24})
Cuadro.loc['Domingo'] = pd.Series({'Madrugada':25, 'Mañana':26, 'Tarde':27,
'Noche':28})
print(Cuadro)
如何创建像这样的图形:
Data Usage:
|Midnight o
|
|Night OOO
| OOO
|Afternoon
|
| o O O ( )
|Morning__________________________________________________________________
M T W Th F Sat Sun
这些点的大小取决于单元格的值? 预先感谢您的任何帮助或建议... 何塞
答案 0 :(得分:3)
data.csv
Day,Midnight,Morning,Afternoon,Night
Monday,4.002900,30.905096,25.193066,23.704473
Tuesday,22.074967,16.407200,50.409445,27.396373
Wednesday,18.875000,28.415111,22.205521,25.744592
Thursday,12.470333,16.265086,15.390797,81.988800
Friday,NaN,33.658050,23.814764,20.096790
Saturday,12.647037,16.545295,25.620673,14.903473
Sunday,4.975500,19.023320,21.215298,45.440120
code.py
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("data.csv")
fig, ax = plt.subplots()
ax.scatter(df['Day'], ['Midnight']*7, s=20*df['Midnight'])
ax.scatter(df['Day'], ['Morning']*7, s=20*df['Morning'])
ax.scatter(df['Day'], ['Afternoon']*7, s=20*df['Afternoon'])
ax.scatter(df['Day'], ['Night']*7, s=20*df['Night'])
plt.ylabel('Time of Day')
plt.xlabel('Day of the Week')
plt.show()
结果图