xxxxxxxxxx
data = np.array([(1, 2, 3), (4, 5, 6), (7, 8, 9)],
dtype=[("a", "i4"), ("b", "i4"), ("c", "i4")])
>>> df3 = pd.DataFrame(data, columns=['c', 'a'])
>>> df3
c a
0 3 1
1 6 4
2 9 7
xxxxxxxxxx
# Python code demonstrate creating
# DataFrame from dict narray / lists
# By default addresses.
import pandas as pd
# intialise data of lists.
data = {'Name':['Tom', 'nick', 'krish', 'jack'],
'Age':[20, 21, 19, 18]}
# Create DataFrame
df = pd.DataFrame(data)
# Print the output.
print(df)
xxxxxxxxxx
import pandas as pd
# Creating a dictionary to store data
data = {'Name':['Tony', 'Steve', 'Bruce', 'Peter' ],
'Age': [35, 70, 45, 20] }
# Creating DataFrame
df = pd.DataFrame(data)
# Print the dataframe
df
xxxxxxxxxx
# import pandas as pd
import pandas as pd
# Calling DataFrame constructor
df = pd.DataFrame()
print(df)
xxxxxxxxxx
d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
col1 col2
0 1 3
1 2 4
xxxxxxxxxx
import pandas as pd
data = {
"calories" : [420, 380, 390],
"duration" : [50, 40, 45]
}
df = pd.DataFrame(data)
print(df)
xxxxxxxxxx
d = {'col1': [1, 2], 'col2': [3, 4]}
>>> df = pd.DataFrame(data=d)
>>> df
col1 col2
0 1 3
1 2 4
xxxxxxxxxx
df = pd.DataFrame(
.: {
"A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], .:
"B": ["one", "one", "two", "three", "two", "two", "one", "three"], .:
"C": np.random.randn(8), .:
"D": np.random.randn(8), .:
.: }
.: )
.:
In [88]: df
Out[88]:
A B C D
0 foo one 1.346061 -1.577585
1 bar one 1.511763 0.396823
2 foo two 1.627081 -0.105381
3 bar three -0.990582 -0.532532
4 foo two -0.441652 1.453749
5 bar two 1.211526 1.208843
6 foo one 0.268520 -0.080952
7 foo three 0.024580 -0.264610