In [6]:
import pandas as pd #Import der Bibliothek pandas
from pandas import Series
In [7]:
objekt = Series([1200,1500,1600,1400,1800])
print objekt
In [10]:
print objekt.values
print objekt.index
In [11]:
objekt2 = Series([1200,1500,1600,1400,1800],index=['Montag','Dienstag','Mittwoch','Donnerstag','Freitag'])
print objekt2
In [12]:
objekt2['Montag']
Out[12]:
In [13]:
objekt2['Donnerstag']=1600
objekt2
Out[13]:
In [14]:
objekt2[objekt2 >1500]
Out[14]:
In [17]:
objekt2 * 3
Out[17]:
In [21]:
staedte = {'Stuttgart': 700000, 'Muenchen': 1000000, 'Hamburg': 800000, 'Koeln': 300000} #Dictionary der Einwohnerzahlen
In [22]:
objekt3 = Series(staedte)
objekt3
Out[22]:
In [23]:
objekt3.name = 'Einwohnerzahl'
objekt3.index.name = 'Stadt'
objekt3
Out[23]:
In [24]:
objekt3.index=['Koeln','Hamburg','Muenchen','Stuttgart'] #Austausch des Indexes durch Zuweisung
objekt3
Out[24]:
In [25]:
objekt3.mean()
Out[25]:
In [1]:
%matplotlib inline
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2014', periods=1000))
ts = ts.cumsum()
ts.plot()
Out[1]:
In [33]:
import numpy as np
import pandas as pd
from pandas import DataFrame #aufpassen wie DataFrame geschrieben wird !
#Erzeugen eines Dataframes aus gleichlangen Listen
daten = {'stadt':['Stuttgart', 'Muenchen', 'Hamburg', 'Koeln','Stuttgart'],'jahr':[2014,2015,2016,2017,2015],'pop':[0.7,0.8,0.9,0.85,0.75]}
frame = DataFrame(daten) #erzeugen des DataFrames
print frame
In [34]:
frame = DataFrame(daten,columns=['stadt','jahr','pop'])
print frame
In [38]:
#Ausgabe spezieller Spalten (Columns)
print frame['jahr']
print '################'
print frame.stadt
In [40]:
#Ausgabe spezieller Zeilen (Rows)
frame.ix[2] #Index als integer
Out[40]:
In [41]:
frame.T
Out[41]:
In [1]:
import numpy as np
import pandas as pd
from pandas import DataFrame
url="sudoku-10.csv"
df = pd.read_csv(url,header=0,sep=';') #sudoku als csv einlesen
#df.describe()
print (df)
In [ ]:
In [14]:
# Using `iloc[]`
print(df.iloc[0][0])
# Using `loc[]`
print(df.loc[0][1])
# Using `at[]`
#print(df.at[0,'1'])
# Using `iat[]`
print(df.iat[0,0])
# Using `get_value(index, column)`
#print(df.get_value(0, '1'))
In [ ]:
https://www.datacamp.com/community/tutorials/pandas-tutorial-dataframe-python#gs.J_F2fGU
In [9]:
# Use `iloc[]` to select a row
print(df.iloc[0])
# Use `loc[]` to select a column
#print(df.loc[:,1])
In [ ]:
In [2]:
import pandas as pd
df.to_csv('myDataFrame10.csv')
In [3]:
import pandas as pd
df.to_csv('myDataFrame20.csv', sep=';', encoding='utf-8')
In [ ]:
In [ ]: