How do I create a pandas DataFrame from another object?

preview_player
Показать описание
Have you ever needed to create a DataFrame of "dummy" data, but without reading from a file? In this video, I'll demonstrate how to create a DataFrame from a dictionary, a list, and a NumPy array. I'll also show you how to create a new Series and attach it to the DataFrame.

SUBSCRIBE to learn data science with Python:

JOIN the "Data School Insiders" community and receive exclusive rewards:

== RESOURCES ==

== RELATED VIDEOS ==

== LET'S CONNECT! ==
Рекомендации по теме
Комментарии
Автор

WIth pandas 0.23.0 and python >= 3.6, the order of columns specified in the dictionary is preserved.
We do not need to specify addition column parameter.
Thanks for the great series btw.

mohitanand
Автор

Great video!
It gives a FutureWarning now when we concatenate (using pd.concat), saying "Sorting because non-concatenation axis is not aligned. A future version
of pandas will change to not sort by default". We can pass the sort=True to by-pass the warning.

vishesharora
Автор

Great video! I'm currently learning Python and this was exactly what I needed to do. Thanks again for sharing.

josevillalba
Автор

Nice work. Now to extend this further consider this question:

How do you assign values to 1) columns, 2) rows and 3) cells?

Here I am hinting at using `apply`, `applymap` for columns and tables, then using the .ix, .iloc, .loc, .at., .iat methods to assigned specific cells.

Example `df.loc[3, "State"] = '"California"'`

pacrii
Автор

I LOVE YOU, U SAVE MY FINAL PROJECT TUT <3

TheFrickAriela
Автор

Excellent explanation. I like your teaching style. Thank you.

ricardojfloresgavidia
Автор

Hi Sir... Hope you are doing well. Love from INDIA <3 . I really like your teaching style and I have learnt a from your videos on Data Science. So can you kindly tell me which books or resources apart from your videos I can use to learn deep about Data Science ? It would be a great help then. Hope to hear back from you Sir. Have a nice day ahead. :)

sayantanchakraborty
Автор

How can I use conditional statement in Data Frame

bekitech
Автор

Can you show how to load a JSON data from the API into pandas dataframe.

vinaybhushan
Автор

Hi! Thank you so much for this video. Not much of a 'Pythoner', I am looking for a way to subtract the trend from a computed time series numpy array x(t) and process the remainder after the subtraction. I think I need to pack the array into a Pandas data frame. So here your video exactly tells me how to proceed. But can you a suggest a Pandas function to get the trend of the x values now packed into the Dataframe as a function of time t?

dr.subratasarangi
Автор

I have a question at 2:21 the output you get. how i can replace 0 1 2 as the timestamp because i am getting the real time sensor data on serial port.

saeedahmed
Автор

hey guy first of all, thanks for your tips it helped me so much.
Man i got a question for you and i think you can help me.
i got TWO dataFrame like this.




Order Company STATUS
1.1 TOTAL OPEN
1.3 CARRIES OPEN
1.4 SPEED FAIL
1.5 TOTAL OPEN
1.6 SPEED IN TRANSIT
1.7 TOTAL OPEN



Order Company STATUS
1.1 TOTAL FINISHED
1.3 CARRIES OPEN
1.4 SPEED FAIL
1.5 TOTAL OPEN
1.6 SPEED FINISHED
1.7 TOTAL FINISHED


I want to make a filter by company and then upgrade the STATUS making something like vlooup in excell, so get back it to the first dataframe.
Im trying to do it but im kinda lost

GuilhermeSilva-levj
Автор

Hi Kevin, I'm getting an error when concatenating df and s.
I'm using Python 3.6.6 (Conda) and Pandas 0.23.4.

I get an error: ValueError: Shape of passed values is (3, 5), indices imply (3, 3)

My code, after creating both the DF and the Series is: pd.concat([df, s], axis=1, sort=False)

I've been looking over StackOverflow, and it seemed in newer versions the sort=False would do the trick. Unfortunately, I keep getting the same error as if it were sort=True or sort=None)

Not including the sort=x would get me FutureWarning: Sorting because non-concatenation axis is not aligned. A future version of pandas will change to not sort by default. The ValueError: Shape of passed values is (3, 5), indices imply (3, 3) remains the same.

On the other hand, if I concatenate on axis=0 I get 5x3 df with 7 NaN values.

Would you mind sharing your thoughts on this?

Many thanks in advance! :)

bo
Автор

Sir I came across this function stack() in dataframe object. can you please help me in clarifying this ?

saiftazir
Автор

Is there a way in which we can add a column called grades as a third column and give the grades according to certain criteria like between 70 to 80 it's B, between 95 - 102 it's A, something like that.

mandalamtarun
Автор

Hi,
I wanted to execute this below correlated query in PANDAS... I have searched many vedios on net but cant find a way to solve this in Pandas.
Below SQL query doesn't work with dataframes..but works with tables.. (Basically, want to update one column of one dataframe(1st) with average values of a column from 2nd dataframe based on some condition.)
Do you have any hint for solving these type of queries?

update dataframe1 set
dataframe1.average_x = ( select avg(dataframe2.rank) from dataframe2
where
dataframe1.id=dataframe2.id &
dataframe2.date >= dataframe1.date &
dataframe2.date <= dataframe1.limitdate );

Thanks!

VijayKumar-dqph
Автор

Hi,
if my dictionaries have different lengths, I'm taking an error : 'arrays must all be same length'
Actually, i had expected to see nan on the table for missing data .
is there any simple way to do that ? :/

yucelozyazgan
Автор

I'm trying to concat two dataframes with 2 columns of same name and same type. I used both concat and append methods and got same result. The format is correct, though there are Nan values being showed and both my dataframes have no missing values.

gauravkamath
Автор

I've watched 30 of your videos so far so thank you so much for the help. Could you make a video about emailing pandas dfs? Is there an easy way to format pandas dfs to a neat table in email? Does this require html knowledge?

BiggiePanda
Автор

could you please explain how to get a nested dictionary(like below) in to a dataframe. thanks in advance!

nested_dict = { 'dictA': {'key_1': 'value_1', 'key_2': 'value_2', 'key_3': 'value_3' },
'dictB': {'key_1': 'value_4', 'key_2': 'value_5', 'key_3': 'value_6'},
..., ..., ...}

lasithauyangoda