Creating pandas dataframes
Pandas dataframe is a 2D data structure which looks like a table. There are different ways to create a dataframe, mostly everybody sticks to few formats they like and stick to it, thats good. But, sometimes when you have a problem and you want somebody's opinion or get a suggestion or solution, you cannot give all your code and ask them to execute and start explaining the problem. Its a lot easier if you could generate a small sample data and explain it and from suggestion/solution you could copy the concept to your main program.
Whenever you ask a question in StackOverflow or any forum and when preparing to ask the question itself, you would know that it would be a lot easier if you provided a sample data and say this the problem you are facing and this what i have tried, so far ? In python pandas world, you need to build small dataframes to build those examples.
Here are few ways of creating new dataframes and generating data.
- Empty dataframe
- Tuple technique
- Dictionary with value lists
- Array of Arrays / Lists of List
- Array of dictionary
- pd.Series to dataframe
- 8x4 dataframe with some random data
- Single column list of alphabets
- dictionary to Dataframe
Empty Dataframe with columns
Here index is the
first tuple variable
Dictionary with value lists
Array of Arrays / Lists of List
Array of dictionary
pd.Series to dataframe
8x4 dataframe with some random data
Single column list of alphabets
dictionary to Dataframe
Here we create dataframe from a complex dictionary